Search in sources :

Example 16 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method bindViewType.

/**
   * ViewType will be classified into {HashMap<Integer,ArrayList<Integer>> mViewTypes}
   *
   * @param component
   */
private void bindViewType(WXComponent component) {
    int id = generateViewType(component);
    if (mViewTypes == null) {
        mViewTypes = new SparseArray<>();
    }
    ArrayList<WXComponent> mTypes = mViewTypes.get(id);
    if (mTypes == null) {
        mTypes = new ArrayList<>();
        mViewTypes.put(id, mTypes);
    }
    mTypes.add(component);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) Point(android.graphics.Point)

Example 17 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method onBeforeScroll.

@Override
public void onBeforeScroll(int dx, int dy) {
    T bounceRecyclerView = getHostView();
    if (mStickyMap == null || bounceRecyclerView == null) {
        return;
    }
    HashMap<String, WXComponent> stickyMap = mStickyMap.get(getRef());
    if (stickyMap == null) {
        return;
    }
    Iterator<Map.Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
    Map.Entry<String, WXComponent> entry;
    WXComponent stickyComponent;
    while (iterator.hasNext()) {
        entry = iterator.next();
        stickyComponent = entry.getValue();
        if (stickyComponent != null && stickyComponent.getDomObject() != null && stickyComponent instanceof WXCell) {
            WXCell cell = (WXCell) stickyComponent;
            if (cell.getHostView() == null) {
                return;
            }
            if (stickyComponent != null && stickyComponent.getDomObject() != null && stickyComponent instanceof WXCell) {
                if (stickyComponent.getHostView() == null) {
                    return;
                }
                RecyclerView.LayoutManager layoutManager;
                boolean beforeFirstVisibleItem = false;
                if ((layoutManager = getHostView().getInnerView().getLayoutManager()) instanceof LinearLayoutManager) {
                    int fVisible = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
                    int pos = mChildren.indexOf(cell);
                    if (pos <= fVisible) {
                        beforeFirstVisibleItem = true;
                    }
                }
                int[] location = new int[2];
                stickyComponent.getHostView().getLocationOnScreen(location);
                int[] parentLocation = new int[2];
                stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);
                int top = location[1] - parentLocation[1];
                boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= 0 && dy >= 0;
                boolean removeSticky = cell.getLocationFromStart() <= 0 && top > 0 && dy <= 0;
                if (showSticky) {
                    bounceRecyclerView.notifyStickyShow(cell);
                } else if (removeSticky) {
                    bounceRecyclerView.notifyStickyRemove(cell);
                }
                cell.setLocationFromStart(top);
            }
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method relocateAppearanceHelper.

private void relocateAppearanceHelper() {
    Iterator<Map.Entry<String, AppearanceHelper>> iterator = mAppearComponents.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<String, AppearanceHelper> item = iterator.next();
        AppearanceHelper value = item.getValue();
        WXComponent dChild = findDirectListChild(value.getAwareChild());
        int index = mChildren.indexOf(dChild);
        value.setCellPosition(index);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap) Point(android.graphics.Point) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 19 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method notifyAppearStateChange.

@Override
public void notifyAppearStateChange(int firstVisible, int lastVisible, int directionX, int directionY) {
    //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;
        }
        boolean outOfVisibleRange = item.getCellPositionINScollable() < firstVisible || item.getCellPositionINScollable() > lastVisible;
        View view = component.getHostView();
        if (view == null) {
            continue;
        }
        boolean visible = (!outOfVisibleRange) && item.isViewVisible();
        int result = item.setAppearStatus(visible);
        if (WXEnvironment.isApkDebugable()) {
            WXLogUtils.d("appear", "item " + item.getCellPositionINScollable() + " result " + result);
        }
        if (result == AppearanceHelper.RESULT_NO_CHANGE) {
            continue;
        }
        component.notifyAppearStateChange(result == AppearanceHelper.RESULT_APPEAR ? Constants.Event.APPEAR : Constants.Event.DISAPPEAR, direction);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) ImageView(android.widget.ImageView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Point(android.graphics.Point) AppearanceHelper(com.taobao.weex.ui.component.AppearanceHelper)

Example 20 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method unBindViewType.

private void unBindViewType(WXComponent component) {
    int id = generateViewType(component);
    if (mViewTypes == null)
        return;
    ArrayList<WXComponent> mTypes = mViewTypes.get(id);
    if (mTypes == null)
        return;
    mTypes.remove(component);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) 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