@Test public void testMoveDom() throws Exception { createBody(); JSONObject obj; obj = new JSONObject(); obj.put("type","div"); obj.put("ref","100"); stmt.addDom(obj,WXDomObject.ROOT,0); obj = new JSONObject(); obj.put("type","div"); obj.put("ref","101"); stmt.addDom(obj,WXDomObject.ROOT,0); stmt.moveDom("100",WXDomObject.ROOT,1); stmt.batch(); }
void moveDom(final String ref, final String parentRef, int index) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); WXDomObject domObject = mRegistry.get(ref); WXDomObject parentObject = mRegistry.get(parentRef); if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT); } return; } if (domObject.parent.equals(parentObject)) { if(parentObject.index(domObject) == index) { return; } else if(domObject.parent.index(domObject)<index){ index = index -1; } } final int newIndex = index; domObject.parent.remove(domObject); parentObject.add(domObject, newIndex); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex); } @Override public String toString() { return "moveDom"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } }
WXDomStatement { void moveDom(final String ref, final String parentRef, int index) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); WXDomObject domObject = mRegistry.get(ref); WXDomObject parentObject = mRegistry.get(parentRef); if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT); } return; } if (domObject.parent.equals(parentObject)) { if(parentObject.index(domObject) == index) { return; } else if(domObject.parent.index(domObject)<index){ index = index -1; } } final int newIndex = index; domObject.parent.remove(domObject); parentObject.add(domObject, newIndex); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex); } @Override public String toString() { return "moveDom"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } } }
WXDomStatement { void moveDom(final String ref, final String parentRef, int index) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); WXDomObject domObject = mRegistry.get(ref); WXDomObject parentObject = mRegistry.get(parentRef); if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT); } return; } if (domObject.parent.equals(parentObject)) { if(parentObject.index(domObject) == index) { return; } else if(domObject.parent.index(domObject)<index){ index = index -1; } } final int newIndex = index; domObject.parent.remove(domObject); parentObject.add(domObject, newIndex); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex); } @Override public String toString() { return "moveDom"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } } WXDomStatement(String instanceId, WXRenderManager renderManager); }
WXDomStatement { void moveDom(final String ref, final String parentRef, int index) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); WXDomObject domObject = mRegistry.get(ref); WXDomObject parentObject = mRegistry.get(parentRef); if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT); } return; } if (domObject.parent.equals(parentObject)) { if(parentObject.index(domObject) == index) { return; } else if(domObject.parent.index(domObject)<index){ index = index -1; } } final int newIndex = index; domObject.parent.remove(domObject); parentObject.add(domObject, newIndex); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex); } @Override public String toString() { return "moveDom"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } } WXDomStatement(String instanceId, WXRenderManager renderManager); void destroy(); void getComponentSize(final String ref, final JSCallback callback); }
WXDomStatement { void moveDom(final String ref, final String parentRef, int index) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); WXDomObject domObject = mRegistry.get(ref); WXDomObject parentObject = mRegistry.get(parentRef); if (domObject == null || domObject.parent == null || parentObject == null || parentObject.hasNewLayout()) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT); } return; } if (domObject.parent.equals(parentObject)) { if(parentObject.index(domObject) == index) { return; } else if(domObject.parent.index(domObject)<index){ index = index -1; } } final int newIndex = index; domObject.parent.remove(domObject); parentObject.add(domObject, newIndex); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex); } @Override public String toString() { return "moveDom"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } } WXDomStatement(String instanceId, WXRenderManager renderManager); void destroy(); void getComponentSize(final String ref, final JSCallback callback);  }