void destroyInstance(String instanceId) { if (TextUtils.isEmpty(instanceId)) { return; } if (!WXUtils.isUiThread()) { throw new WXRuntimeException("[WXSDKManager] destroyInstance error"); } mWXRenderManager.removeRenderStatement(instanceId); mWXDomManager.removeDomStatement(instanceId); mBridgeManager.destroyInstance(instanceId); WXModuleManager.destroyInstanceModules(instanceId); }
/** * Batch the execution of command objects and execute all the command objects created other * places, e.g. call {@link IWXRenderTask#execute()}. First, it will rebuild the dom tree and do * pre layout staff. Then call {@link * com.taobao.weex.dom.flex.CSSNode#calculateLayout(CSSLayoutContext)} to start calculate layout. * Next, call {@link #applyUpdate(WXDomObject)} to get changed dom and creating corresponding * command object. Finally, walk through the queue, e.g. call {@link IWXRenderTask#execute()} for * every task in the queue. */ void batch() { long start0 = System.currentTimeMillis(); if (!mDirty || mDestroy) { return; } WXDomObject rootDom = mRegistry.get(WXDomObject.ROOT); if (rootDom == null) { return; } rebuildingDomTree(rootDom); layoutBefore(rootDom); long start = System.currentTimeMillis(); rootDom.calculateLayout(mLayoutContext); WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if (instance != null) { instance.cssLayoutTime(System.currentTimeMillis() - start); } layoutAfter(rootDom); start = System.currentTimeMillis(); applyUpdate(rootDom); if (instance != null) { instance.applyUpdateTime(System.currentTimeMillis() - start); } start = System.currentTimeMillis(); updateDomObj(); if (instance != null) { instance.updateDomObjTime(System.currentTimeMillis() - start); } parseAnimation(); int count = mNormalTasks.size(); for (int i = 0; i < count && !mDestroy; ++i) { mWXRenderManager.runOnThread(mInstanceId, mNormalTasks.get(i)); } mNormalTasks.clear(); mAddDom.clear(); animations.clear(); mDirty = false; if (instance != null) { instance.batchTime(System.currentTimeMillis() - start0); } }
/** * Create a command object for adding a dom node to its parent in a specific location. If dom's * parent doesn't exist or the dom has been added in current {@link WXSDKInstance}, this method * will return. If the above request is met, then put the command object in the queue. * * @param dom the dom object in the form of JSONObject * @param parentRef parent to which the dom is added. * @param index the location of which the dom is added. */ 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); // Create component in dom thread final WXComponent component = mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index); if (component == null) { // stop redner, some fatal happened. 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); } }
/** * Create command object for creating body according to the JSONObject. And put the command object * in the queue. * * @param element the jsonObject according to which to create command object. */ void createBody(JSONObject element) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if (element == null) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_CREATEBODY); } return; } WXDomObject domObject = parseInner(element); if (domObject == null) { return; } Map<String, Object> style = new HashMap<>(5); if (!domObject.getStyles().containsKey(Constants.Name.FLEX_DIRECTION)) { style.put(Constants.Name.FLEX_DIRECTION, "column"); } if (!domObject.getStyles().containsKey(Constants.Name.BACKGROUND_COLOR)) { style.put(Constants.Name.BACKGROUND_COLOR, "#ffffff"); } // If there is height or width in JS, then that value will override value here. if (!domObject.getStyles().containsKey(Constants.Name.WIDTH)) { style.put( Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId))); domObject.setModifyWidth(true); } if (!domObject.getStyles().containsKey(Constants.Name.HEIGHT)) { style.put( Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId))); domObject.setModifyHeight(true); } WXDomObject.prepareRoot(domObject); domObject.updateStyle(style); transformStyle(domObject, true); try { final WXComponent component = mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject); 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.createBody(mInstanceId, component); } catch (Exception e) { WXLogUtils.e("create body failed.", e); } } @Override public String toString() { return "createBody"; } }); 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); } } catch (Exception e) { WXLogUtils.e("create body in dom thread failed." + e.getMessage()); } }
void createInstance( WXSDKInstance instance, String code, Map<String, Object> options, String jsonInitData) { mWXRenderManager.createInstance(instance, instance.getInstanceId()); mBridgeManager.createInstance(instance.getInstanceId(), code, options, jsonInitData); }
public void postOnUiThread(Runnable runnable, long delayMillis) { mWXRenderManager.postOnUiThread(runnable, delayMillis); }
public WXSDKInstance getSDKInstance(String instanceId) { return mWXRenderManager.getWXSDKInstance(instanceId); }