Skip to content

Commit

Permalink
Add parameter to use new incremental mount in inbox
Browse files Browse the repository at this point in the history
Summary: This will not use the Scroll listener but the View's offset and translation methods if isNewIncrementalMountEnabled.

Reviewed By: pasqualeanatriello

Differential Revision: D4810889

fbshipit-source-id: 540caf18a64fc7328fb61c269c8eb3b413110b97
  • Loading branch information
Byron Hood authored and facebook-github-bot committed Apr 3, 2017
1 parent 4e8b910 commit f06473e
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class RecyclerBinder implements Binder<RecyclerView>, LayoutInfo.Componen
private final ComponentContext mComponentContext;
private final RangeScrollListener mRangeScrollListener = new RangeScrollListener();
private final LayoutHandlerFactory mLayoutHandlerFactory;
private final boolean mUseNewIncrementalMount;

// Data structure to be used to hold Components and ComponentTreeHolders before adding them to
// the RecyclerView. This happens in the case of inserting something inside the current working
Expand All @@ -77,7 +78,15 @@ public RecyclerBinder(
ComponentContext componentContext,
float rangeRatio,
LayoutInfo layoutInfo) {
this(componentContext, rangeRatio, layoutInfo, null);
this(componentContext, rangeRatio, layoutInfo, null, false);
}

public RecyclerBinder(
ComponentContext componentContext,
float rangeRatio,
LayoutInfo layoutInfo,
@Nullable LayoutHandlerFactory layoutHandlerFactory) {
this(componentContext, rangeRatio, layoutInfo, layoutHandlerFactory, false);
}

/**
Expand All @@ -92,14 +101,16 @@ public RecyclerBinder(
* the {@link LayoutManager} this RecyclerBinder will use.
* @param layoutHandlerFactory the RecyclerBinder will use this layoutHandlerFactory when creating
* {@link ComponentTree}s in order to specify on which thread layout calculation should happen.
* Pass null to use the default components layout thread.
* @param useNewIncrementalMount
*/
public RecyclerBinder(
ComponentContext componentContext,
float rangeRatio,
LayoutInfo layoutInfo,
@Nullable LayoutHandlerFactory layoutHandlerFactory) {
@Nullable LayoutHandlerFactory layoutHandlerFactory,
boolean useNewIncrementalMount) {
mComponentContext = componentContext;
mUseNewIncrementalMount = useNewIncrementalMount;
mComponentTreeHolders = new ArrayList<>();
mPendingComponentTreeHolders = new ArrayList<>();
mInternalAdapter = new InternalAdapter();
Expand All @@ -111,11 +122,11 @@ public RecyclerBinder(
}

public RecyclerBinder(ComponentContext c) {
this(c, 4f, new LinearLayoutInfo(c, VERTICAL, false), null);
this(c, 4f, new LinearLayoutInfo(c, VERTICAL, false), null, false);
}

public RecyclerBinder(ComponentContext c, LayoutInfo layoutInfo) {
this(c, 4f, layoutInfo, null);
this(c, 4f, layoutInfo, null, false);
}

/**
Expand Down Expand Up @@ -711,7 +722,9 @@ private class RangeScrollListener extends RecyclerView.OnScrollListener {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

IncrementalMountUtils.performIncrementalMount(recyclerView);
if (!mUseNewIncrementalMount) {
IncrementalMountUtils.performIncrementalMount(recyclerView);
}

final int firstVisiblePosition = mLayoutInfo.findFirstVisiblePosition();
final int lastVisiblePosition = mLayoutInfo.findLastVisiblePosition();
Expand Down Expand Up @@ -747,7 +760,8 @@ private class InternalAdapter extends RecyclerView.Adapter {

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ComponentViewHolder(new ComponentView(mComponentContext));
return new ComponentViewHolder(
new ComponentView(mComponentContext, null, mUseNewIncrementalMount));
}

@Override
Expand Down

0 comments on commit f06473e

Please sign in to comment.