Search in sources :

Example 1 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView in project weex-example by KalicyZhou.

the class BasicListComponent method addEvent.

@Override
public void addEvent(String type) {
    super.addEvent(type);
    if (Constants.Event.SCROLL.equals(type) && getHostView() != null && getHostView().getInnerView() != null) {
        WXRecyclerView innerView = getHostView().getInnerView();
        innerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int offsetX = recyclerView.computeHorizontalScrollOffset();
                int offsetY = recyclerView.computeVerticalScrollOffset();
                if (shouldReport(offsetX, offsetY)) {
                    int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
                    int contentHeight = recyclerView.computeVerticalScrollRange();
                    Map<String, Object> event = new HashMap<>(2);
                    Map<String, Object> contentSize = new HashMap<>(2);
                    Map<String, Object> contentOffset = new HashMap<>(2);
                    contentSize.put(Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(contentWidth, getInstance().getViewPortWidth()));
                    contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getViewPortWidth()));
                    contentOffset.put(Constants.Name.X, -WXViewUtils.getWebPxByWidth(offsetX, getInstance().getViewPortWidth()));
                    contentOffset.put(Constants.Name.Y, -WXViewUtils.getWebPxByWidth(offsetY, getInstance().getViewPortWidth()));
                    event.put(Constants.Name.CONTENT_SIZE, contentSize);
                    event.put(Constants.Name.CONTENT_OFFSET, contentOffset);
                    fireEvent(Constants.Event.SCROLL, event);
                }
            }
        });
    }
}
Also used : WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap) Point(android.graphics.Point)

Example 2 with WXRecyclerView

use of com.taobao.weex.ui.view.listview.WXRecyclerView in project weex-example by KalicyZhou.

the class BasicListComponent method setScrollable.

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

Example 3 with WXRecyclerView

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

the class BasicListComponent method onHostViewInitialized.

@Override
protected void onHostViewInitialized(T host) {
    super.onHostViewInitialized(host);
    WXRecyclerView recyclerView = host.getInnerView();
    if (recyclerView == null || recyclerView.getAdapter() == null) {
        WXLogUtils.e(TAG, "RecyclerView is not found or Adapter is not bound");
        return;
    }
    if (WXUtils.getBoolean(getDomObject().getAttrs().get("prefetchGapDisable"), false)) {
        if (recyclerView.getLayoutManager() != null) {
            recyclerView.getLayoutManager().setItemPrefetchEnabled(false);
        }
    }
    if (mChildren == null) {
        WXLogUtils.e(TAG, "children is null");
        return;
    }
    mDragHelper = new DefaultDragHelper(mChildren, recyclerView, new EventTrigger() {

        @Override
        public void triggerEvent(String type, Map<String, Object> args) {
            fireEvent(type, args);
        }
    });
    mTriggerType = getTriggerType(getDomObject());
}
Also used : WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) ArrayMap(android.support.v4.util.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with WXRecyclerView

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

the class BasicListComponent method scrollTo.

@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
    float offsetFloat = 0;
    boolean smooth = true;
    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());
            }
        }
    }
    final int offset = (int) offsetFloat;
    T bounceRecyclerView = getHostView();
    if (bounceRecyclerView == null) {
        return;
    }
    WXComponent parent = component;
    WXCell cell = null;
    while (parent != null) {
        if (parent instanceof WXCell) {
            cell = (WXCell) parent;
            break;
        }
        parent = parent.getParent();
    }
    if (cell != null) {
        final int pos = mChildren.indexOf(cell);
        if (pos == -1) {
            // Invalid position
            return;
        }
        final WXRecyclerView view = bounceRecyclerView.getInnerView();
        view.scrollTo(smooth, pos, offset, getOrientation());
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) Point(android.graphics.Point)

Example 5 with WXRecyclerView

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

the class WXRecyclerTemplateList method setColumnWidth.

@WXComponentProp(name = Constants.Name.COLUMN_WIDTH)
public void setColumnWidth(int columnCount) {
    if (mDomObject.getColumnWidth() != mColumnWidth) {
        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)

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