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