Search in sources :

Example 1 with WXErrorCode

use of com.taobao.weex.common.WXErrorCode in project weex-example by KalicyZhou.

the class WXDomStatement method addDomInternal.

/**
   * Add DOM node.
   * @param dom
   * @param isRoot
   * @param parentRef
   * @param index
   */
private void addDomInternal(JSONObject dom, boolean isRoot, String parentRef, final int index) {
    if (mDestroy) {
        return;
    }
    WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
    if (instance == null) {
        return;
    }
    WXErrorCode errCode = isRoot ? WXErrorCode.WX_ERR_DOM_CREATEBODY : WXErrorCode.WX_ERR_DOM_ADDELEMENT;
    if (dom == null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
    }
    //only non-root has parent.
    WXDomObject parent;
    WXDomObject domObject = WXDomObject.parse(dom, instance);
    if (domObject == null || mRegistry.containsKey(domObject.getRef())) {
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.e("[WXDomStatement] " + (isRoot ? "createBody" : "addDom") + " error,DOM object is null or already registered!!");
        }
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
        return;
    }
    if (isRoot) {
        WXDomObject.prepareRoot(domObject, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)), WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId), WXSDKManager.getInstanceViewPortWidth(mInstanceId)));
    } else if ((parent = mRegistry.get(parentRef)) == null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
        return;
    } else {
        //non-root and parent exist
        parent.add(domObject, index);
    }
    domObject.traverseTree(mAddDOMConsumer, ApplyStyleConsumer.getInstance());
    //Create component in dom thread
    WXComponent component = isRoot ? mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject) : mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index);
    if (component == null) {
        instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
        //stop redner, some fatal happened.
        return;
    }
    AddDomInfo addDomInfo = new AddDomInfo();
    addDomInfo.component = component;
    mAddDom.put(domObject.getRef(), addDomInfo);
    IWXRenderTask task = isRoot ? new CreateBodyTask(component) : new AddDOMTask(component, parentRef, index);
    mNormalTasks.add(task);
    addAnimationForDomTree(domObject);
    mDirty = true;
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}
Also used : WXErrorCode(com.taobao.weex.common.WXErrorCode) IWXRenderTask(com.taobao.weex.ui.IWXRenderTask) WXSDKInstance(com.taobao.weex.WXSDKInstance) WXComponent(com.taobao.weex.ui.component.WXComponent)

Aggregations

WXSDKInstance (com.taobao.weex.WXSDKInstance)1 WXErrorCode (com.taobao.weex.common.WXErrorCode)1 IWXRenderTask (com.taobao.weex.ui.IWXRenderTask)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1