Search in sources :

Example 81 with WXComponent

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;
    }
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) EventResult(com.taobao.weex.bridge.EventResult) JSONObject(com.alibaba.fastjson.JSONObject) WXComponent(com.taobao.weex.ui.component.WXComponent) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) ArrayStack(com.taobao.weex.el.parse.ArrayStack) HashMap(java.util.HashMap) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) WXCell(com.taobao.weex.ui.component.list.WXCell) WXAttr(com.taobao.weex.dom.WXAttr)

Example 82 with WXComponent

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);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Scrollable(com.taobao.weex.ui.component.Scrollable)

Example 83 with WXComponent

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());
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Scrollable(com.taobao.weex.ui.component.Scrollable)

Example 84 with WXComponent

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);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) Point(android.graphics.Point) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 85 with WXComponent

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;
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) Point(android.graphics.Point)

Aggregations

WXComponent (com.taobao.weex.ui.component.WXComponent)101 Point (android.graphics.Point)21 WXDomObject (com.taobao.weex.dom.WXDomObject)20 WXVContainer (com.taobao.weex.ui.component.WXVContainer)19 HashMap (java.util.HashMap)13 View (android.view.View)9 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)9 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)9 Map (java.util.Map)9 Test (org.junit.Test)9 ArrayMap (android.support.v4.util.ArrayMap)8 RecyclerView (android.support.v7.widget.RecyclerView)8 JSONObject (com.alibaba.fastjson.JSONObject)8 WXSDKInstance (com.taobao.weex.WXSDKInstance)8 ComponentTest (com.taobao.weex.ui.component.ComponentTest)8 WXDivTest (com.taobao.weex.ui.component.WXDivTest)8 Scrollable (com.taobao.weex.ui.component.Scrollable)6 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)6 WXHeaderTest (com.taobao.weex.ui.component.WXHeaderTest)6 AppearanceHelper (com.taobao.weex.ui.component.AppearanceHelper)5