Search in sources :

Example 1 with WXCellDomObject

use of com.taobao.weex.dom.WXCellDomObject in project incubator-weex by apache.

the class StatementTest method createVForNode.

private WXCell createVForNode() throws Exception {
    WXCell cell = new WXCell(WXSDKInstanceTest.createInstance(), new WXCellDomObject(), null, false);
    final WXDiv div = new WXDiv(WXSDKInstanceTest.createInstance(), new WXDomObject(), cell);
    cell.addChild(div);
    WXText text = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
    WXStatement statement = new WXStatement();
    statement.put("[[repeat]]", ELUtils.vforBlock(JSON.parse("{\n" + "      '@expression': 'dataList',\n" + "      '@index': 'index',\n" + "      '@alias': 'item'\n" + "    }")));
    WXDomObject domObject = (WXDomObject) text.getDomObject();
    domObject.getAttrs().setStatement(statement);
    div.addChild(text);
    PowerMockito.mockStatic(WXComponentFactory.class, new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            WXText renderNode = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
            return renderNode;
        }
    });
    return cell;
}
Also used : Answer(org.mockito.stubbing.Answer) WXDiv(com.taobao.weex.ui.component.WXDiv) WXDomObject(com.taobao.weex.dom.WXDomObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject) TestDomObject(com.taobao.weex.dom.TestDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXTextDomObject(com.taobao.weex.dom.WXTextDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXText(com.taobao.weex.ui.component.WXText) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell) WXStatement(com.taobao.weex.dom.binding.WXStatement)

Example 2 with WXCellDomObject

use of com.taobao.weex.dom.WXCellDomObject in project incubator-weex by apache.

the class AbstractAddElementAction method addDomInternal.

/**
 * Add DOM node.
 */
protected void addDomInternal(DOMActionContext context, JSONObject dom) {
    if (context.isDestory()) {
        return;
    }
    WXSDKInstance instance = context.getInstance();
    if (instance == null) {
        return;
    }
    String errMsg = getErrorMsg();
    if (dom == null) {
        // instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
        WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), getErrorCode(), "addDomInternal", errMsg, null);
    }
    // only non-root has parent.
    Stopwatch.tick();
    WXDomObject domObject = WXDomObject.parse(dom, instance, null);
    Stopwatch.split("parseDomObject");
    if (domObject == null || context.getDomByRef(domObject.getRef()) != null) {
        WXLogUtils.e("[DOMActionContextImpl] " + getStatementName() + " error,DOM object is null or already registered!!");
        // instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
        WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), getErrorCode(), "addDomInternal", errMsg, null);
        return;
    }
    appendDomToTree(context, domObject);
    Stopwatch.split("appendDomToTree");
    int maxDomDep = domObject.traverseTree(context.getAddDOMConsumer(), context.getApplyStyleConsumer());
    if (instance.getMaxDomDeep() < maxDomDep) {
        instance.setMaxDomDeep(maxDomDep);
    }
    Stopwatch.split("traverseTree");
    // Create component in dom thread
    WXComponent component = createComponent(context, domObject);
    if (component == null) {
        // WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), errCode, "addDomInternal", errMsg, null);
        return;
    }
    Stopwatch.split("createComponent");
    boolean needAddDomInfo = true;
    if (domObject.getType().equals(WXBasicComponentType.CELL_SLOT) && domObject instanceof WXCellDomObject) {
        needAddDomInfo = false;
    }
    if (needAddDomInfo) {
        context.addDomInfo(domObject.getRef(), component);
    }
    context.postRenderTask(this);
    addAnimationForDomTree(context, domObject);
    // instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
    if (WXTracing.isAvailable()) {
        List<Stopwatch.ProcessEvent> events = Stopwatch.getProcessEvents();
        for (Stopwatch.ProcessEvent event : events) {
            submitPerformance(event.fname, "X", context.getInstanceId(), event.duration, event.startMillis, true);
        }
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent) Stopwatch(com.taobao.weex.tracing.Stopwatch) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject)

Example 3 with WXCellDomObject

use of com.taobao.weex.dom.WXCellDomObject in project incubator-weex by apache.

the class WXRecyclerTemplateList method addChild.

@Override
public void addChild(WXComponent child, int index) {
    /**
     *  dom object in component is not tree, build tree
     */
    if (!(child instanceof WXCell)) {
        super.addChild(child, index);
    }
    if (child instanceof WXBaseRefresh) {
        return;
    }
    if (child instanceof WXCell) {
        if (child.getDomObject() != null && child.getDomObject().getAttrs() != null) {
            Object templateId = child.getDomObject().getAttrs().get(Constants.Name.Recycler.SLOT_TEMPLATE_CASE);
            String key = WXUtils.getString(templateId, null);
            if (getDomObject().getAttrs().containsKey(Constants.Name.Recycler.LIST_DATA_TEMPLATE_SWITCH_KEY)) {
                if (defaultTemplateCell == null) {
                    defaultTemplateCell = (WXCell) child;
                    if (!TextUtils.isEmpty(key)) {
                        defaultTemplateKey = key;
                    } else {
                        key = defaultTemplateKey;
                        child.getDomObject().getAttrs().put(Constants.Name.Recycler.SLOT_TEMPLATE_CASE, key);
                    }
                }
            } else {
                if (defaultTemplateCell == null || child.getDomObject().getAttrs().containsKey(Constants.Name.Recycler.SLOT_TEMPLATE_DEFAULT)) {
                    defaultTemplateCell = (WXCell) child;
                    if (!TextUtils.isEmpty(key)) {
                        defaultTemplateKey = key;
                    } else {
                        key = defaultTemplateKey;
                        child.getDomObject().getAttrs().put(Constants.Name.Recycler.SLOT_TEMPLATE_CASE, key);
                    }
                }
            }
            if (key != null) {
                if (child.getDomObject() instanceof WXCellDomObject && getDomObject() instanceof WXRecyclerDomObject) {
                    WXCellDomObject domObject = (WXCellDomObject) child.getDomObject();
                    domObject.setRecyclerDomObject((WXRecyclerDomObject) getDomObject());
                }
                mTemplateSources.put(key, (WXCell) child);
                renderTemplateCellWithData((WXCell) child);
                if (mTemplateViewTypes.get(key) == null) {
                    mTemplateViewTypes.put(key, mTemplateViewTypes.size());
                }
            }
        }
        notifyUpdateList();
    }
}
Also used : WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell)

Example 4 with WXCellDomObject

use of com.taobao.weex.dom.WXCellDomObject in project incubator-weex by apache.

the class WXRecyclerTemplateList method copyComponentFromSourceCell.

/**
 * copy cell component from source, init render data, and return source
 * if none data, return null
 */
public WXComponent copyComponentFromSourceCell(WXCell cell) {
    renderTemplateCellWithData(cell);
    WXCell component = (WXCell) Statements.copyComponentTree(cell);
    if (component.getDomObject() instanceof WXCellDomObject && getDomObject() instanceof WXRecyclerDomObject) {
        WXCellDomObject domObject = (WXCellDomObject) component.getDomObject();
        domObject.setRecyclerDomObject((WXRecyclerDomObject) getDomObject());
    }
    component.setRenderData(cell.getRenderData());
    return component;
}
Also used : WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXCell(com.taobao.weex.ui.component.list.WXCell)

Aggregations

WXCellDomObject (com.taobao.weex.dom.WXCellDomObject)4 WXDomObject (com.taobao.weex.dom.WXDomObject)3 WXCell (com.taobao.weex.ui.component.list.WXCell)3 JSONObject (com.alibaba.fastjson.JSONObject)2 WXRecyclerDomObject (com.taobao.weex.dom.WXRecyclerDomObject)2 WXSDKInstance (com.taobao.weex.WXSDKInstance)1 TestDomObject (com.taobao.weex.dom.TestDomObject)1 WXTextDomObject (com.taobao.weex.dom.WXTextDomObject)1 WXStatement (com.taobao.weex.dom.binding.WXStatement)1 Stopwatch (com.taobao.weex.tracing.Stopwatch)1 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 WXDiv (com.taobao.weex.ui.component.WXDiv)1 WXText (com.taobao.weex.ui.component.WXText)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1