use of com.taobao.weex.ui.component.list.WXCell in project incubator-weex by apache.
the class Statements method doBindingAttrsEventAndRenderChildNode.
/**
* bind attrs and doRender component child
*/
private static void doBindingAttrsEventAndRenderChildNode(WXComponent component, WXDomObject domObject, CellRenderContext context, List<WXComponent> updates) {
WXAttr attr = component.getDomObject().getAttrs();
/**
* sub component supported, sub component new stack
*/
ArrayStack stack = context.stack;
if (attr.get(ELUtils.IS_COMPONENT_ROOT) != null && WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)) {
if (attr.get(ELUtils.COMPONENT_PROPS) != null && attr.get(ELUtils.COMPONENT_PROPS) instanceof JSONObject) {
String compoentId = (String) attr.get(CellDataManager.SUB_COMPONENT_TEMPLATE_ID);
Object compoentData = null;
if (!TextUtils.isEmpty(compoentId)) {
String virtualComponentId = context.getRenderState().getVirtualComponentIds().get(component.getViewTreeKey());
if (virtualComponentId == null) {
// none virtualComponentId, create and do attach
virtualComponentId = CellDataManager.createVirtualComponentId(context.templateList.getRef(), component.getViewTreeKey(), context.templateList.getItemId(context.position));
Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
EventResult result = WXBridgeManager.getInstance().syncCallJSEventWithResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, compoentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.CREATE, new Object[] { virtualComponentId, props }, null);
if (result != null && result.getResult() != null && result.getResult() instanceof Map) {
props.putAll((Map<? extends String, ?>) result.getResult());
}
compoentData = props;
context.getRenderState().getVirtualComponentIds().put(component.getViewTreeKey(), virtualComponentId);
context.templateList.getCellDataManager().createVirtualComponentData(context.position, virtualComponentId, compoentData);
// create virtual componentId
WXBridgeManager.getInstance().asyncCallJSEventVoidResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.ATTACH, null);
} else {
// get virtual component data check has dirty's update
compoentData = context.getRenderState().getVirtualComponentDatas().get(virtualComponentId);
if (context.getRenderState().isHasDataUpdate()) {
Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
EventResult result = WXBridgeManager.getInstance().syncCallJSEventWithResult(WXBridgeManager.METHD_COMPONENT_HOOK_SYNC, component.getInstanceId(), null, virtualComponentId, VirtualComponentLifecycle.LIFECYCLE, VirtualComponentLifecycle.SYNSTATE, new Object[] { virtualComponentId, props }, null);
if (result != null && result.getResult() != null && result.getResult() instanceof Map) {
props.putAll((Map<? extends String, ?>) result.getResult());
context.templateList.getCellDataManager().updateVirtualComponentData(virtualComponentId, props);
compoentData = props;
}
}
}
component.getDomObject().getAttrs().put(CellDataManager.VIRTUAL_COMPONENT_ID, virtualComponentId);
} else {
// stateless component
Map<String, Object> props = renderProps((JSONObject) attr.get(ELUtils.COMPONENT_PROPS), context.stack);
compoentData = props;
}
// virtual component is new context
context.stack = new ArrayStack();
if (compoentData != null) {
context.stack.push(compoentData);
}
}
}
/**
* check node is render only once, if render once, and has rendered, just return
*/
Object vonce = null;
if (attr.getStatement() != null) {
vonce = attr.getStatement().get(WXStatement.WX_ONCE);
}
if (vonce != null) {
ArrayStack onceStack = context.getRenderState().getOnceComponentStates().get(component.getViewTreeKey());
if (onceStack == null) {
onceStack = context.templateList.copyStack(context, stack);
context.getRenderState().getOnceComponentStates().put(component.getViewTreeKey(), onceStack);
}
context.stack = onceStack;
}
doRenderBindingAttrsAndEvent(component, domObject, context);
if (component instanceof WXVContainer) {
if (!domObject.isShow()) {
if (!(component instanceof WXCell)) {
return;
}
}
WXVContainer container = (WXVContainer) component;
for (int k = 0; k < container.getChildCount(); ) {
WXComponent next = container.getChild(k);
k += doRenderComponent(next, context, updates);
}
}
if (stack != context.stack) {
context.stack = stack;
}
}
use of com.taobao.weex.ui.component.list.WXCell in project incubator-weex by apache.
the class Statements method getComponentId.
public static String getComponentId(WXComponent component) {
if (component instanceof WXCell || component == null) {
return null;
}
WXDomObject domObject = (WXDomObject) component.getDomObject();
WXAttr attr = domObject.getAttrs();
if (attr.get(ELUtils.IS_COMPONENT_ROOT) != null && WXUtils.getBoolean(attr.get(ELUtils.IS_COMPONENT_ROOT), false)) {
if (attr.get(ELUtils.COMPONENT_PROPS) != null && attr.get(ELUtils.COMPONENT_PROPS) instanceof JSONObject) {
Object componentId = attr.get(CellDataManager.VIRTUAL_COMPONENT_ID);
if (componentId == null) {
return null;
}
return componentId.toString();
}
}
return getComponentId(component.getParent());
}
use of com.taobao.weex.ui.component.list.WXCell in project incubator-weex by apache.
the class WXRecyclerTemplateList method calcContentOffset.
public int calcContentOffset(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
int offset = 0;
for (int i = 0; i < firstVisibleItemPosition; i++) {
WXCell cell = getSourceTemplate(i);
if (cell == null) {
continue;
}
offset -= cell.getLayoutHeight();
}
if (layoutManager instanceof GridLayoutManager) {
int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
offset = offset / spanCount;
}
View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
if (firstVisibleView != null) {
offset += firstVisibleView.getTop();
}
return offset;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
int firstVisibleItemPosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(null)[0];
int offset = 0;
for (int i = 0; i < firstVisibleItemPosition; i++) {
WXCell cell = getSourceTemplate(i);
if (cell == null) {
continue;
}
offset -= cell.getLayoutHeight();
}
offset = offset / spanCount;
View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
if (firstVisibleView != null) {
offset += firstVisibleView.getTop();
}
return offset;
}
return -1;
}
use of com.taobao.weex.ui.component.list.WXCell 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.ui.component.list.WXCell 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