Search in sources :

Example 6 with BounceRecyclerView

use of com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView in project incubator-weex by apache.

the class BasicListComponent method onBeforeScroll.

@Override
public void onBeforeScroll(int dx, int dy) {
    T bounceRecyclerView = getHostView();
    if (mStickyMap == null || bounceRecyclerView == null) {
        return;
    }
    Map<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;
    int currentStickyPos = -1;
    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;
            }
            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];
            RecyclerView.LayoutManager layoutManager;
            boolean beforeFirstVisibleItem = false;
            boolean removeOldSticky = false;
            layoutManager = getHostView().getInnerView().getLayoutManager();
            if (layoutManager instanceof LinearLayoutManager || layoutManager instanceof GridLayoutManager) {
                int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
                int lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
                int pos = mChildren.indexOf(cell);
                cell.setScrollPositon(pos);
                if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition && top <= cell.getStickyOffset())) {
                    beforeFirstVisibleItem = true;
                    if (pos > currentStickyPos) {
                        currentStickyPos = pos;
                    }
                } else {
                    removeOldSticky = true;
                }
            } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                int[] firstItems = new int[3];
                int firstVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(firstItems)[0];
                int lastVisiblePosition = ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(firstItems)[0];
                int pos = mChildren.indexOf(cell);
                if (pos <= firstVisiblePosition || (cell.getStickyOffset() > 0 && firstVisiblePosition < pos && pos <= lastVisiblePosition && top <= cell.getStickyOffset())) {
                    beforeFirstVisibleItem = true;
                    if (pos > currentStickyPos) {
                        currentStickyPos = pos;
                    }
                } else {
                    removeOldSticky = true;
                }
            }
            boolean showSticky = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= cell.getStickyOffset() && dy >= 0;
            boolean removeSticky = cell.getLocationFromStart() <= cell.getStickyOffset() && top > cell.getStickyOffset() && dy <= 0;
            if (showSticky) {
                bounceRecyclerView.notifyStickyShow(cell);
            } else if (removeSticky || removeOldSticky) {
                bounceRecyclerView.notifyStickyRemove(cell);
            }
            cell.setLocationFromStart(top);
        }
    }
    if (currentStickyPos >= 0) {
        bounceRecyclerView.updateStickyView(currentStickyPos);
    } else {
        if (bounceRecyclerView instanceof BounceRecyclerView) {
            ((BounceRecyclerView) bounceRecyclerView).getStickyHeaderHelper().clearStickyHeaders();
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point) 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) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with BounceRecyclerView

use of com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView in project incubator-weex by apache.

the class WXRecyclerTemplateList method scrollTo.

@JSMethod
public void scrollTo(int position, Map<String, Object> options) {
    if (position >= 0) {
        boolean smooth = true;
        if (options != null) {
            smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
        }
        final int pos = position;
        BounceRecyclerView bounceRecyclerView = getHostView();
        if (bounceRecyclerView == null) {
            return;
        }
        final WXRecyclerView view = bounceRecyclerView.getInnerView();
        view.scrollTo(smooth, pos, 0, getOrientation());
    }
}
Also used : BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) Point(android.graphics.Point) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 8 with BounceRecyclerView

use of com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView in project incubator-weex by apache.

the class WXRecyclerTemplateList method scrollTo.

@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
    float offsetFloat = 0;
    boolean smooth = true;
    int position = -1;
    int typeIndex = -1;
    if (options != null) {
        String offsetStr = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
        smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
        if (offsetStr != null) {
            try {
                offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), getInstance().getInstanceViewPortWidth());
            } catch (Exception e) {
                WXLogUtils.e("Float parseFloat error :" + e.getMessage());
            }
        }
        position = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.CELL_INDEX), -1);
        typeIndex = WXUtils.getNumberInt(options.get(Constants.Name.Recycler.TYPE_INDEX), -1);
    }
    WXCell cell = findCell(component);
    if (typeIndex >= 0) {
        if (cellDataManager.listData != null && component.getRef() != null) {
            int typePosition = 0;
            for (int i = 0; i < cellDataManager.listData.size(); i++) {
                WXCell template = getSourceTemplate(i);
                if (template == null) {
                    continue;
                }
                if (cell.getRef().equals(template.getRef())) {
                    typePosition++;
                }
                if (typePosition > typeIndex) {
                    position = i;
                    break;
                }
            }
            if (position < 0) {
                position = cellDataManager.listData.size() - 1;
            }
        }
    }
    final int offset = (int) offsetFloat;
    BounceRecyclerView bounceRecyclerView = getHostView();
    if (bounceRecyclerView == null) {
        return;
    }
    if (position >= 0) {
        final int pos = position;
        final WXRecyclerView view = bounceRecyclerView.getInnerView();
        view.scrollTo(smooth, pos, offset, getOrientation());
    }
}
Also used : BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) Point(android.graphics.Point) WXCell(com.taobao.weex.ui.component.list.WXCell)

Aggregations

BounceRecyclerView (com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView)8 Point (android.graphics.Point)5 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)3 TargetApi (android.annotation.TargetApi)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 ViewTreeObserver (android.view.ViewTreeObserver)2 ICheckBindingScroller (com.taobao.weex.common.ICheckBindingScroller)2 OnWXScrollListener (com.taobao.weex.common.OnWXScrollListener)2 WXCell (com.taobao.weex.ui.component.list.WXCell)2 RecyclerViewBaseAdapter (com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ArrayMap (android.support.v4.util.ArrayMap)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 JSMethod (com.taobao.weex.annotation.JSMethod)1