Search in sources :

Example 21 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView 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 22 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.

the class WXRecyclerTemplateList method setColumnGap.

@WXComponentProp(name = Constants.Name.COLUMN_GAP)
public void setColumnGap(float columnGap) throws InterruptedException {
    if (mDomObject.getColumnGap() != mColumnGap) {
        updateRecyclerAttr();
        WXRecyclerView wxRecyclerView = getHostView().getInnerView();
        wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
    }
}
Also used : WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) WXComponentProp(com.taobao.weex.ui.component.WXComponentProp)

Example 23 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.

the class WXRecyclerTemplateList method addEvent.

@Override
public void addEvent(String type) {
    super.addEvent(type);
    if (ScrollStartEndHelper.isScrollEvent(type) && getHostView() != null && getHostView().getInnerView() != null && !mHasAddScrollEvent) {
        mHasAddScrollEvent = true;
        WXRecyclerView innerView = getHostView().getInnerView();
        innerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            private int offsetXCorrection, offsetYCorrection;

            private boolean mFirstEvent = true;

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                if (!layoutManager.canScrollVertically()) {
                    return;
                }
                int offsetX = recyclerView.computeHorizontalScrollOffset();
                int offsetY = recyclerView.computeVerticalScrollOffset();
                if (dx == 0 && dy == 0) {
                    offsetXCorrection = offsetX;
                    offsetYCorrection = offsetY;
                    offsetX = 0;
                    offsetY = 0;
                } else {
                    offsetX = offsetX - offsetXCorrection;
                    offsetY = offsetY - offsetYCorrection;
                }
                getScrollStartEndHelper().onScrolled(offsetX, offsetY);
                if (!getDomObject().getEvents().contains(Constants.Event.SCROLL)) {
                    return;
                }
                if (mFirstEvent) {
                    // skip first event
                    mFirstEvent = false;
                    return;
                }
                if (shouldReport(offsetX, offsetY)) {
                    fireScrollEvent(recyclerView, offsetX, offsetY);
                }
            }
        });
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) BounceRecyclerView(com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) Point(android.graphics.Point)

Example 24 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView in project incubator-weex by apache.

the class WXRecyclerTemplateList method setScrollable.

@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
    WXRecyclerView inner = getHostView().getInnerView();
    inner.setScrollable(scrollable);
}
Also used : WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) WXComponentProp(com.taobao.weex.ui.component.WXComponentProp)

Example 25 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView 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

WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)26 WXComponentProp (com.taobao.weex.ui.component.WXComponentProp)13 Point (android.graphics.Point)7 RecyclerView (android.support.v7.widget.RecyclerView)4 BounceRecyclerView (com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)3 ArrayMap (android.support.v4.util.ArrayMap)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)2 WXComponent (com.taobao.weex.ui.component.WXComponent)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSMethod (com.taobao.weex.annotation.JSMethod)1 WXRuntimeException (com.taobao.weex.common.WXRuntimeException)1 WXCell (com.taobao.weex.ui.component.list.WXCell)1