com.taobao.weex.ui.view.listview.WXRecyclerView Java Examples

The following examples show how to use com.taobao.weex.ui.view.listview.WXRecyclerView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WXAttr.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public int getLayoutType(){
  Object obj = get(Constants.Name.LAYOUT);
  if (obj == null) {
    return WXRecyclerView.TYPE_LINEAR_LAYOUT;
  }

  try {
    switch(String.valueOf(obj)){
      case Constants.Value.MULTI_COLUMN :
        return  WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT;
      case Constants.Value.GRID :
        return  WXRecyclerView.TYPE_GRID_LAYOUT;
      default:
        return WXRecyclerView.TYPE_LINEAR_LAYOUT;
    }
  } catch (Exception e) {
    WXLogUtils.e("[WXAttr] getLayoutType:", e);
  }
  return WXRecyclerView.TYPE_LINEAR_LAYOUT;
}
 
Example #2
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@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 (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());
}
 
Example #3
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProperties(Map<String, Object> props) {
  super.updateProperties(props);
  if(props.containsKey(Constants.Name.PADDING)
          ||props.containsKey(Constants.Name.PADDING_LEFT)
          || props.containsKey(Constants.Name.PADDING_RIGHT)){

    if(mPaddingLeft !=mDomObject.getPadding().get(Spacing.LEFT)
            || mPaddingRight !=mDomObject.getPadding().get(Spacing.RIGHT)) {

      markComponentUsable();
      updateRecyclerAttr();
      WXRecyclerView wxRecyclerView = getHostView().getInnerView();
      wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
    }
  }

}
 
Example #4
Source File: ScreenShot.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
public static View findFirstListByRootView(View  rootView){
    View firstListView = null;
    if(null != rootView){
        allViews = ViewUtil.getAllChildViews(rootView);
        for (View view:allViews
                ) {
            if(view instanceof WXRecyclerView){
                firstListView = view;
                break;
            }
        }
    }
    return firstListView;
}
 
Example #5
Source File: ScreenShot.java    From WeexOne with MIT License 5 votes vote down vote up
public static View findFirstListByRootView(View  rootView){
    View firstListView = null;
    if(null != rootView){
        allViews = ViewUtil.getAllChildViews(rootView);
        for (View view:allViews
                ) {
            if(view instanceof WXRecyclerView){
                firstListView = view;
                break;
            }
        }
    }
    return firstListView;
}
 
Example #6
Source File: ComponentHeightComputer.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
static int computeComponentContentHeight(@NonNull WXComponent component) {
    View view = component.getHostView();
    if(view == null) {
        return 0;
    }
    if(component instanceof WXListComponent) {
        WXListComponent listComponent = (WXListComponent) component;
        BounceRecyclerView bounceRecyclerView = listComponent.getHostView();
        if(bounceRecyclerView == null) {
            return 0;
        }
        WXRecyclerView innerView = bounceRecyclerView.getInnerView();
        if(innerView == null) {
            return bounceRecyclerView.getMeasuredHeight();
        } else {
            return innerView.computeVerticalScrollRange();
        }
    } else if(component instanceof WXScroller) {
        WXScroller scroller = (WXScroller) component;
        if(!ViewUtils.isVerticalScroller(scroller)) {
            return view.getMeasuredHeight();
        }
        ViewGroup group = scroller.getInnerView();
        if(group == null) {
            return view.getMeasuredHeight();
        }
        if(group.getChildCount() != 1) {
            return view.getMeasuredHeight();
        } else {
            return group.getChildAt(0).getMeasuredHeight();
        }
    } else {
        return view.getMeasuredHeight();
    }
}
 
Example #7
Source File: BasicListComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
  View inner = getHostView().getInnerView();
  if (inner instanceof WXRecyclerView) {
    ((WXRecyclerView) inner).setScrollable(scrollable);
  }
  ;
}
 
Example #8
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
  this.isScrollable = scrollable;
  WXRecyclerView inner = getHostView().getInnerView();
  if(inner != null) {
    inner.setScrollable(scrollable);
  }
}
 
Example #9
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.COLUMN_GAP)
public void setColumnGap(float columnGap) throws InterruptedException {
  if(mDomObject.getColumnGap() != mColumnGap) {
    markComponentUsable();
    updateRecyclerAttr();
    WXRecyclerView wxRecyclerView = getHostView().getInnerView();
    wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
  }
}
 
Example #10
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.COLUMN_WIDTH)
public void setColumnWidth(int columnCount)  {
  if(mDomObject.getColumnWidth() != mColumnWidth){
    markComponentUsable();
    updateRecyclerAttr();
    WXRecyclerView wxRecyclerView = getHostView().getInnerView();
    wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation());
  }
}
 
Example #11
Source File: BenchmarkTest.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
private long calcTime() {
  BenchmarkActivity benchmarkActivity = mActivityRule.getActivity();
  benchmarkActivity.loadWeexPage("http://30.8.53.163:8080/complicated.js");
  onView(withClassName(Matchers.is(WXRecyclerView.class.getName()))).perform
      (RecyclerViewActions.scrollToPosition(0));
  return benchmarkActivity.getWXInstance().getWXPerformance().screenRenderTime;
}
 
Example #12
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public WXListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) {
  super(instance, node, parent);
  if (node != null && node instanceof WXRecyclerDomObject) {
    mDomObject = (WXRecyclerDomObject) node;
    mDomObject.preCalculateCellWidth();

    if(WXBasicComponentType.WATERFALL.equals(node.getType())){
      mLayoutType = WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT;
    }else{
      mLayoutType = mDomObject.getLayoutType();
    }
    updateRecyclerAttr();

  }
}
 
Example #13
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.COLUMN_COUNT)
public void setColumnCount(int columnCount){
  if(mDomObject.getColumnCount() != mColumnCount){
    markComponentUsable();
    updateRecyclerAttr();
    WXRecyclerView wxRecyclerView = getHostView().getInnerView();
    wxRecyclerView.initView(getContext(), mLayoutType,mColumnCount,mColumnGap,getOrientation());
  }
}
 
Example #14
Source File: BounceRecyclerView.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public WXRecyclerView setInnerView(Context context) {
  WXRecyclerView wxRecyclerView = new WXRecyclerView(context);
  wxRecyclerView.initView(context, WXRecyclerView.TYPE_LINEAR_LAYOUT, getOrientation());
  return wxRecyclerView;
}
 
Example #15
Source File: BounceRecyclerView.java    From weex with Apache License 2.0 4 votes vote down vote up
@Override
public WXRecyclerView setInnerView(Context context) {
    WXRecyclerView wxRecyclerView = new WXRecyclerView(context);
    wxRecyclerView.initView(context, WXRecyclerView.TYPE_LINEAR_LAYOUT, getOrientation());
    return wxRecyclerView;
}
 
Example #16
Source File: BounceRecyclerView.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@Override
public WXRecyclerView setInnerView(Context context) {
  WXRecyclerView wxRecyclerView = new WXRecyclerView(context);
  wxRecyclerView.initView(context, mLayoutType,mColumnCount,mColumnGap,getOrientation());
  return wxRecyclerView;
}
 
Example #17
Source File: BasicListComponent.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public void scrollTo(WXComponent component, final int offset) {
  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) {
    int pos = mChildren.indexOf(cell);
    final WXRecyclerView view = bounceRecyclerView.getInnerView();
    view.scrollToPosition(pos);
    final WXComponent cellComp = cell;
    //scroll cell to top
    view.postDelayed(new Runnable() {
      @Override
      public void run() {
        if (cellComp.getHostView() == null) {
          return;
        }
        View cellView = cellComp.getHostView();
        if (getOrientation() == Constants.Orientation.VERTICAL) {
          int scrollY = cellView.getTop() + offset;
          view.smoothScrollBy(0, scrollY);
        } else {
          int scrollX = cellView.getLeft() + offset;
          view.smoothScrollBy(scrollX, 0);
        }
      }
    }, 50);

  }

}
 
Example #18
Source File: SimpleRecyclerView.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@Override
public WXRecyclerView getInnerView() {
  return this;
}
 
Example #19
Source File: SimpleListComponent.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
protected SimpleRecyclerView generateListView(Context context, int orientation) {
  SimpleRecyclerView view = new SimpleRecyclerView(context);
  view.initView(context, WXRecyclerView.TYPE_LINEAR_LAYOUT, orientation);
  return view;
}
 
Example #20
Source File: SimpleRecyclerView.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public WXRecyclerView getInnerView() {
  return this;
}
 
Example #21
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@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() {
        private int offsetXCorrection, offsetYCorrection;
        private boolean mFirstEvent = true;

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
          super.onScrolled(recyclerView, dx, dy);
//          WXLogUtils.e("SCROLL", dx + ", " + dy + ", " + recyclerView.computeHorizontalScrollRange()
//          + ", " + recyclerView.computeVerticalScrollRange()
//          + ", " + recyclerView.computeHorizontalScrollOffset()
//          + ", " + recyclerView.computeVerticalScrollOffset());

          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;
          }

          if (mFirstEvent) {
            //skip first event
            mFirstEvent = false;
            return;
          }

          if (shouldReport(offsetX, offsetY)) {
            fireScrollEvent(recyclerView, offsetX, offsetY);
          }
        }
      });
    }
  }
 
Example #22
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@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);
    final WXRecyclerView view = bounceRecyclerView.getInnerView();

    if (!smooth) {
      RecyclerView.LayoutManager layoutManager = view.getLayoutManager();
      if (layoutManager instanceof LinearLayoutManager) {
        //GridLayoutManager is also instance of LinearLayoutManager
        ((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
      } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
      }
      //Any else?
    } else {
      view.smoothScrollToPosition(pos);
      if (offset != 0) {
        view.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
              if (getOrientation() == Constants.Orientation.VERTICAL) {
                recyclerView.smoothScrollBy(0, offset);
              } else {
                recyclerView.smoothScrollBy(offset, 0);
              }
              recyclerView.removeOnScrollListener(this);
            }
          }
        });
      }
    }
  }
}
 
Example #23
Source File: SimpleListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@Override
protected SimpleRecyclerView generateListView(Context context, int orientation) {
  return generateListView(context,WXRecyclerView.TYPE_LINEAR_LAYOUT,orientation);
}
 
Example #24
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@WXComponentProp(name = Constants.Name.SCROLLABLE)
public void setScrollable(boolean scrollable) {
  WXRecyclerView inner = getHostView().getInnerView();
  inner.setScrollable(scrollable);
}
 
Example #25
Source File: ListComponentView.java    From weex-uikit with MIT License votes vote down vote up
WXRecyclerView getInnerView(); 
Example #26
Source File: ListComponentView.java    From ucar-weex-core with Apache License 2.0 votes vote down vote up
WXRecyclerView getInnerView();