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));
}
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);
}
}
}
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);
}
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);
}
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);
}
}
Aggregations