/** * Bind a recyclerView to Tangram. After calling this, {@link GroupBasicAdapter}, {@link VirtualLayoutManager} are auto binded. * * @param view A plain recyclerView with no adapter or layoutManager binded. */ public void bindView(@NonNull final RecyclerView view) { //noinspection ConstantConditions Preconditions.checkArgument(view != null, "view must not be null"); if (mContentView != null) { mContentView.setAdapter(null); mContentView.setLayoutManager(null); } this.mContentView = view; this.mContentView.setLayoutManager(mLayoutManager); mLayoutManager.setPerformanceMonitor(mPerformanceMonitor); if (mGroupBasicAdapter == null) { this.mGroupBasicAdapter = mAdapterBuilder.newAdapter(mContext, mLayoutManager, this); mGroupBasicAdapter.setPerformanceMonitor(mPerformanceMonitor); mGroupBasicAdapter.setErrorSupport(getService(InternalErrorSupport.class)); } if (mContentView.getRecycledViewPool() != null) { mContentView.setRecycledViewPool(new InnerRecycledViewPool(mContentView.getRecycledViewPool())); } register(GroupBasicAdapter.class, mGroupBasicAdapter); register(RecyclerView.RecycledViewPool.class, mContentView.getRecycledViewPool()); this.mContentView.setAdapter(mGroupBasicAdapter); if (VERSION.SDK_INT < 21) { this.mContentView.setChildDrawingOrderCallback(new DrawingOrderCallback()); } }
public SectionsRecyclerView(Context context, RecyclerView recyclerView) { super(context); mRecyclerView = recyclerView; // We need to draw first visible item on top of other children to support sticky headers mRecyclerView.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() { @Override public int onGetChildDrawingOrder(int childCount, int i) { return childCount - 1 - i; } }); // ViewCache doesn't work well with RecyclerBinder which assumes that whenever item comes back // to viewport it should be rebound which does not happen with ViewCache. Consider this case: // LithoView goes out of screen and it is added to ViewCache, then its ComponentTree is assigned // to another LV which means our LithoView's ComponentTree reference is nullified. It comes back // to screen and it is not rebound therefore we will see 0 height LithoView which actually // happened in multiple product surfaces. Disabling it fixes the issue. mRecyclerView.setItemViewCacheSize(0); addView(mRecyclerView); mStickyHeader = new LithoView(new ComponentContext(getContext()), null); mStickyHeader.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); addView(mStickyHeader); }
/** * Bind a recyclerView to Tangram. After calling this, {@link GroupBasicAdapter}, {@link VirtualLayoutManager} are auto binded. * @param view A plain recyclerView with no adapter or layoutManager binded. */ public void bindView(@NonNull final RecyclerView view) { //noinspection ConstantConditions Preconditions.checkArgument(view != null, "view must not be null"); if (mContentView != null) { mContentView.setAdapter(null); mContentView.setLayoutManager(null); } this.mContentView = view; this.mContentView.setLayoutManager(mLayoutManager); mLayoutManager.setPerformanceMonitor(mPerformanceMonitor); if (mGroupBasicAdapter == null) { this.mGroupBasicAdapter = mAdapterBuilder.newAdapter(mContext, mLayoutManager, this); mGroupBasicAdapter.setPerformanceMonitor(mPerformanceMonitor); mGroupBasicAdapter.setErrorSupport(getService(InternalErrorSupport.class)); } if (mContentView.getRecycledViewPool() != null) { mContentView.setRecycledViewPool(new InnerRecycledViewPool(mContentView.getRecycledViewPool())); } register(GroupBasicAdapter.class, mGroupBasicAdapter); register(RecyclerView.RecycledViewPool.class, mContentView.getRecycledViewPool()); this.mContentView.setAdapter(mGroupBasicAdapter); if (VERSION.SDK_INT < 21) { this.mContentView.setChildDrawingOrderCallback(new DrawingOrderCallback()); } }
List<Article> articles = dataProvider.getArticles(); adapter.setArticles(articles); recyclerView.setChildDrawingOrderCallback(new RecyclerView.ChildDrawingOrderCallback() { @Override public int onGetChildDrawingOrder(int childCount, int i) {