Search in sources :

Example 26 with WXDomObject

use of com.taobao.weex.dom.WXDomObject in project weex-example by KalicyZhou.

the class WXDivTest method testAddChild.

@Test
public void testAddChild() {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    TestDomObject.setRef(testDom, "2");
    WXText child1 = new WXText(instance, testDom, mWXDiv);
    child1.initView();
    mWXDiv.addChild(child1, 0);
    assertEquals(1, mWXDiv.childCount());
    WXDomObject testDom2 = Mockito.spy(new WXDomObject());
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    TestDomObject.setRef(testDom2, "3");
    child2 = new WXText(instance, testDom2, mWXDiv);
    child2.initView();
    mWXDiv.addChild(child2, -1);
    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));
    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    TestDomObject.setRef(testDom3, "4");
    WXText child3 = new WXText(instance, testDom3, mWXDiv);
    child3.initView();
    mWXDiv.addChild(child3, 1);
    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) Spacing(com.taobao.weex.dom.flex.Spacing) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Example 27 with WXDomObject

use of com.taobao.weex.dom.WXDomObject 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 28 with WXDomObject

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

the class WXTransition method asynchronouslyUpdateLayout.

@SuppressWarnings("unused")
public static void asynchronouslyUpdateLayout(WXComponent component, String propertyName, float propertyValue) {
    if (component == null || TextUtils.isEmpty(propertyName)) {
        return;
    }
    String instanceId = component.getInstanceId();
    DOMActionContext domActionContext = WXSDKManager.getInstance().getWXDomManager().getDomContext(instanceId);
    if (domActionContext == null) {
        return;
    }
    WXDomObject domObject = domActionContext.getDomByRef(component.getRef());
    if (domObject == null || TextUtils.isEmpty(instanceId)) {
        return;
    }
    updateShadowLayoutPropertyByName(domObject, propertyName, propertyValue);
    domActionContext.markDirty();
    WXSDKManager.getInstance().getWXDomManager().sendEmptyMessageDelayed(WXDomHandler.MsgType.WX_DOM_TRANSITION_BATCH, 0);
}
Also used : WXDomObject(com.taobao.weex.dom.WXDomObject) DOMActionContext(com.taobao.weex.dom.DOMActionContext)

Example 29 with WXDomObject

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

the class RemoveEventAction method executeDom.

@Override
public void executeDom(DOMActionContext context) {
    if (context.isDestory()) {
        return;
    }
    WXSDKInstance instance = context.getInstance();
    WXDomObject domObject = context.getDomByRef(mRef);
    if (domObject == null) {
        if (instance != null) {
            WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), WXErrorCode.WX_KEY_EXCEPTION_DOM_REMOVE_EVENT, "updateAttr", WXErrorCode.WX_KEY_EXCEPTION_DOM_REMOVE_EVENT.getErrorMsg() + "domObject is null", null);
        }
        return;
    }
    domObject.removeEvent(mEvent);
    mUpdatedDomObject = domObject;
    context.postRenderTask(this);
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject)

Example 30 with WXDomObject

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

the class UpdateAttributeAction method executeDom.

@Override
public void executeDom(DOMActionContext context) {
    if (context.isDestory()) {
        return;
    }
    if (mData == null) {
        return;
    }
    WXSDKInstance instance = context.getInstance();
    final WXDomObject domObject = context.getDomByRef(mRef);
    if (domObject == null) {
        if (instance != null) {
            WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), WXErrorCode.WX_KEY_EXCEPTION_DOM_UPDATE_ATTRS, "updateAttr", WXErrorCode.WX_KEY_EXCEPTION_DOM_UPDATE_ATTRS.getErrorMsg() + "domObject is null", null);
        }
        return;
    }
    domObject.getAttrs().filterBindingStatement(mData);
    domObject.updateAttr(mData);
    if (mData.size() > 0) {
        context.postRenderTask(this);
    }
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject)

Aggregations

WXDomObject (com.taobao.weex.dom.WXDomObject)42 WXSDKInstance (com.taobao.weex.WXSDKInstance)15 WXComponent (com.taobao.weex.ui.component.WXComponent)10 JSONObject (com.alibaba.fastjson.JSONObject)8 WXVContainer (com.taobao.weex.ui.component.WXVContainer)8 Spacing (com.taobao.weex.dom.flex.Spacing)7 WXEvent (com.taobao.weex.dom.WXEvent)6 WXTextDomObject (com.taobao.weex.dom.WXTextDomObject)6 Test (org.junit.Test)6 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)5 Before (org.junit.Before)5 ArrayMap (android.support.v4.util.ArrayMap)4 WXAttr (com.taobao.weex.dom.WXAttr)4 WXDiv (com.taobao.weex.ui.component.WXDiv)4 WXCell (com.taobao.weex.ui.component.list.WXCell)4 HashMap (java.util.HashMap)4 WXStyle (com.taobao.weex.dom.WXStyle)3 FlatGUIContext (com.taobao.weex.ui.flat.FlatGUIContext)3 Map (java.util.Map)3 SpannableString (android.text.SpannableString)2