WXDomStatement { void moveDom(final String ref, final String parentRef, final 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)){ return ; } domObject.parent.remove(domObject); parentObject.add(domObject, index); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, index); } @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(); static final String CHILDREN; static final String TYPE; }
@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(); }