Search in sources :

Example 96 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXRecyclerTemplateList method createChildViewAt.

/**
 * all child is template, none need onCreate child except loading and refresh.
 */
@Override
public void createChildViewAt(int index) {
    int indexToCreate = index;
    if (indexToCreate < 0) {
        indexToCreate = childCount() - 1;
        if (indexToCreate < 0) {
            return;
        }
    }
    final WXComponent child = getChild(indexToCreate);
    if (child instanceof WXBaseRefresh) {
        child.createView();
        setRefreshOrLoading(child);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) Point(android.graphics.Point)

Example 97 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXRecyclerTemplateList method notifyAppearStateChange.

/**
 * first fire appear event.
 */
@Override
public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) {
    if (mAppearHelpers == null || mAppearHelpers.size() <= 0) {
        return;
    }
    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;
    }
    RecyclerView recyclerView = getHostView().getInnerView();
    for (int position = firstVisible; position <= lastVisible; position++) {
        int type = getItemViewType(position);
        List<AppearanceHelper> helpers = mAppearHelpers.get(type);
        if (helpers == null) {
            continue;
        }
        for (AppearanceHelper helper : helpers) {
            if (!helper.isWatch()) {
                continue;
            }
            TemplateViewHolder itemHolder = (TemplateViewHolder) recyclerView.findViewHolderForAdapterPosition(position);
            if (itemHolder == null || itemHolder.getComponent() == null) {
                break;
            }
            List<WXComponent> childListeners = findChildListByRef(itemHolder.getComponent(), helper.getAwareChild().getRef());
            if (childListeners == null || childListeners.size() == 0) {
                break;
            }
            Map<String, Map<Integer, List<Object>>> disAppearList = mDisAppearWatchList.get(position);
            if (disAppearList == null) {
                disAppearList = new ArrayMap<>();
                mDisAppearWatchList.put(position, disAppearList);
            }
            Map<Integer, List<Object>> componentDisAppearList = disAppearList.get(helper.getAwareChild().getRef());
            if (componentDisAppearList == null) {
                componentDisAppearList = new ArrayMap<>();
                disAppearList.put(helper.getAwareChild().getRef(), componentDisAppearList);
            }
            for (int m = 0; m < childListeners.size(); m++) {
                WXComponent childLisener = childListeners.get(m);
                if (childLisener.getHostView() == null) {
                    continue;
                }
                boolean appear = helper.isViewVisible(childLisener.getHostView());
                int key = childLisener.getHostView().hashCode();
                if (appear) {
                    if (!componentDisAppearList.containsKey(key)) {
                        childLisener.notifyAppearStateChange(Constants.Event.APPEAR, direction);
                        List<Object> eventArgs = null;
                        if (childLisener.getDomObject().getEvents() != null && childLisener.getDomObject().getEvents().getEventBindingArgsValues() != null && childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR) != null) {
                            eventArgs = childLisener.getDomObject().getEvents().getEventBindingArgsValues().get(Constants.Event.DISAPPEAR);
                        }
                        componentDisAppearList.put(key, eventArgs);
                    }
                } else {
                    if (componentDisAppearList.containsKey(key)) {
                        childLisener.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
                        componentDisAppearList.remove(key);
                    }
                }
            }
        }
    }
    // handle disappear event, out of position
    int count = getItemCount();
    for (int position = 0; position < count; position++) {
        if (position >= firstVisible && position <= lastVisible) {
            position = lastVisible + 1;
            continue;
        }
        Map<String, Map<Integer, List<Object>>> map = mDisAppearWatchList.get(position);
        if (map == null) {
            continue;
        }
        WXCell template = mTemplateSources.get(getTemplateKey(position));
        if (template == null) {
            return;
        }
        Set<Map.Entry<String, Map<Integer, List<Object>>>> cellWatcherEntries = map.entrySet();
        for (Map.Entry<String, Map<Integer, List<Object>>> cellWatcherEntry : cellWatcherEntries) {
            String ref = cellWatcherEntry.getKey();
            WXComponent component = findChildByRef(template, ref);
            if (component == null) {
                continue;
            }
            Map<Integer, List<Object>> eventWatchers = cellWatcherEntry.getValue();
            if (eventWatchers == null || eventWatchers.size() == 0) {
                continue;
            }
            WXEvent events = component.getDomObject().getEvents();
            Set<Map.Entry<Integer, List<Object>>> eventWatcherEntries = eventWatchers.entrySet();
            for (Map.Entry<Integer, List<Object>> eventWatcherEntry : eventWatcherEntries) {
                events.putEventBindingArgsValue(Constants.Event.DISAPPEAR, eventWatcherEntry.getValue());
                component.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
            }
            eventWatchers.clear();
        }
        mDisAppearWatchList.remove(position);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Point(android.graphics.Point) WXCell(com.taobao.weex.ui.component.list.WXCell) WXEvent(com.taobao.weex.dom.WXEvent) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) WXCellDomObject(com.taobao.weex.dom.WXCellDomObject) WXRecyclerDomObject(com.taobao.weex.dom.WXRecyclerDomObject) List(java.util.List) ArrayList(java.util.ArrayList) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 98 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXRecyclerTemplateList method findChildListByRef.

/**
 * find child list, has same ref
 */
public List<WXComponent> findChildListByRef(WXComponent component, String ref) {
    WXComponent child = findChildByRef(component, ref);
    if (child == null) {
        return null;
    }
    List<WXComponent> componentList = new ArrayList<>();
    WXVContainer container = child.getParent();
    if (container != null && (!(container instanceof WXRecyclerTemplateList))) {
        for (int i = 0; i < container.getChildCount(); i++) {
            WXComponent element = container.getChild(i);
            if (ref.equals(element.getRef())) {
                componentList.add(element);
            }
        }
    } else {
        componentList.add(child);
    }
    return componentList;
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXComponent(com.taobao.weex.ui.component.WXComponent) ArrayList(java.util.ArrayList) Point(android.graphics.Point)

Example 99 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXRecyclerTemplateList method unbindStickStyle.

@Override
public void unbindStickStyle(WXComponent component) {
    WXComponent template = findParentType(component, WXCell.class);
    if (template == null || cellDataManager.listData == null || mStickyHelper == null) {
        return;
    }
    if (mStickyHelper.getStickyTypes().contains(template.getRef())) {
        mStickyHelper.getStickyTypes().remove(template.getRef());
        notifyUpdateList();
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 100 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXScrollView method procSticky.

private View procSticky(Map<String, Map<String, WXComponent>> mStickyMap) {
    if (mStickyMap == null) {
        return null;
    }
    Map<String, WXComponent> stickyMap = mStickyMap.get(mWAScroller.getRef());
    if (stickyMap == null) {
        return null;
    }
    Iterator<Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
    Entry<String, WXComponent> entry = null;
    WXComponent stickyData;
    while (iterator.hasNext()) {
        entry = iterator.next();
        stickyData = entry.getValue();
        getLocationOnScreen(stickyScrollerP);
        stickyData.getHostView().getLocationOnScreen(stickyViewP);
        int parentH = 0;
        if (stickyData.getParent() != null && stickyData.getParent().getRealView() != null) {
            parentH = stickyData.getParent().getRealView().getHeight();
        }
        int stickyViewH = stickyData.getHostView().getHeight();
        int stickyShowPos = stickyScrollerP[1];
        int stickyStartHidePos = -parentH + stickyScrollerP[1] + stickyViewH;
        if (stickyViewP[1] <= stickyShowPos && stickyViewP[1] >= (stickyStartHidePos - stickyViewH)) {
            mStickyOffset = stickyViewP[1] - stickyStartHidePos;
            stickyData.setStickyOffset(stickyViewP[1] - stickyScrollerP[1]);
            return stickyData.getHostView();
        } else {
            stickyData.setStickyOffset(0);
        }
    }
    return null;
}
Also used : Entry(java.util.Map.Entry) WXComponent(com.taobao.weex.ui.component.WXComponent) SuppressLint(android.annotation.SuppressLint)

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