use of com.taobao.weex.ui.component.WXComponent 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.WXComponent in project incubator-weex by apache.
the class WXStickyHelper method bindStickStyle.
public void bindStickStyle(WXComponent component, Map<String, Map<String, WXComponent>> mStickyMap) {
Scrollable scroller = component.getParentScroller();
if (scroller == null) {
return;
}
Map<String, WXComponent> stickyMap = mStickyMap.get(scroller.getRef());
if (stickyMap == null) {
stickyMap = new ConcurrentHashMap<>();
}
if (stickyMap.containsKey(component.getRef())) {
return;
}
stickyMap.put(component.getRef(), component);
mStickyMap.put(scroller.getRef(), stickyMap);
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXStickyHelper method unbindStickStyle.
public void unbindStickStyle(WXComponent component, Map<String, Map<String, WXComponent>> mStickyMap) {
Scrollable scroller = component.getParentScroller();
if (scroller == null) {
return;
}
Map<String, WXComponent> stickyMap = mStickyMap.get(scroller.getRef());
if (stickyMap == null) {
return;
}
stickyMap.remove(component.getRef());
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class BasicListComponent method notifyAppearStateChange.
@Override
public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) {
if (mAppearComponentsRunnable != null) {
getHostView().removeCallbacks(mAppearComponentsRunnable);
mAppearComponentsRunnable = null;
}
// notify appear state
Iterator<AppearanceHelper> it = mAppearComponents.values().iterator();
String direction = directionY > 0 ? Constants.Value.DIRECTION_UP : directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
if (getOrientation() == Constants.Orientation.HORIZONTAL && directionX != 0) {
direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_RIGHT;
}
while (it.hasNext()) {
AppearanceHelper item = it.next();
WXComponent component = item.getAwareChild();
if (!item.isWatch()) {
continue;
}
View view = component.getHostView();
if (view == null) {
continue;
}
boolean outOfVisibleRange = !ViewCompat.isAttachedToWindow(view);
boolean visible = (!outOfVisibleRange) && item.isViewVisible(true);
int result = item.setAppearStatus(visible);
if (result == AppearanceHelper.RESULT_NO_CHANGE) {
continue;
}
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("appear", "item " + item.getCellPositionINScollable() + " result " + result);
}
component.notifyAppearStateChange(result == AppearanceHelper.RESULT_APPEAR ? Constants.Event.APPEAR : Constants.Event.DISAPPEAR, direction);
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class BasicListComponent method calcContentOffset.
public int calcContentOffset(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstVisibleItemPosition == -1) {
return 0;
}
View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
int firstVisibleViewOffset = 0;
if (firstVisibleView != null) {
firstVisibleViewOffset = firstVisibleView.getTop();
}
int offset = 0;
for (int i = 0; i < firstVisibleItemPosition; i++) {
WXComponent child = getChild(i);
if (child != null) {
offset -= child.getLayoutHeight();
}
}
if (layoutManager instanceof GridLayoutManager) {
int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
offset = offset / spanCount;
}
offset += firstVisibleViewOffset;
return offset;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
int firstVisibleItemPosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(null)[0];
if (firstVisibleItemPosition == -1) {
return 0;
}
View firstVisibleView = layoutManager.findViewByPosition(firstVisibleItemPosition);
int firstVisibleViewOffset = 0;
if (firstVisibleView != null) {
firstVisibleViewOffset = firstVisibleView.getTop();
}
int offset = 0;
for (int i = 0; i < firstVisibleItemPosition; i++) {
WXComponent child = getChild(i);
if (child != null) {
offset -= child.getLayoutHeight();
}
}
offset = offset / spanCount;
offset += firstVisibleViewOffset;
return offset;
}
// Unhandled LayoutManager type
return -1;
}
Aggregations