WXDomStatement { void addDom(JSONObject dom, final String parentRef, final int index) { if (mDestroy) { return; } WXDomObject parent = mRegistry.get(parentRef); WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if (parent == null) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_ADDELEMENT); } return; } WXDomObject domObject = parseInner(dom); if (domObject == null || mRegistry.containsKey(domObject.getRef())) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXDomStatement] addDom error!!"); } if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_ADDELEMENT); } return; } findFixed(domObject); parent.add(domObject, index); transformStyle(domObject, true); final WXComponent component = mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index); if(component == null){ return; } AddDomInfo addDomInfo = new AddDomInfo(); addDomInfo.component = component; mAddDom.put(domObject.getRef(), addDomInfo); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if(instance == null || instance.getContext()== null) { WXLogUtils.e("instance is null or instance is destroy!"); return; } try { mWXRenderManager.addComponent(mInstanceId, component, parentRef, index); }catch (Exception e){ WXLogUtils.e("add component failed.", e); } } @Override public String toString() { return "AddDom"; } }); animations.add(new Pair<String, Map<String, Object>>(domObject.getRef(),domObject.getStyles())); 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 testAddDom() throws Exception { createBody(); JSONObject obj = new JSONObject(); obj.put("type","div"); obj.put("ref","100"); stmt.addDom(obj,WXDomObject.ROOT,0); stmt.batch(); }