Skip to content

Commit

Permalink
Promote requestMountForPrefetchedItems to be part of builder
Browse files Browse the repository at this point in the history
Summary: As pre-mounting could be used in different surfaces, it doesn't make sense anymore to put it as a global setting. This diff is to move the param into RecyclerBinder.Builder and make it possible to be customized by users themselves.

Reviewed By: fabiocarballo

Differential Revision: D44269730

fbshipit-source-id: f4277ccff2e7221290f819b7ea0e9904629198ee
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Mar 22, 2023
1 parent 8137d68 commit 5a58dfa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class RecyclerBinderConfiguration {
private boolean mEnableStableIds;
private final boolean mEnableItemPrefetch;
private final int mItemViewCacheSize;
private final boolean mRequestMountForPrefetchedItems;
private LayoutThreadPoolConfiguration mThreadPoolConfiguration =
ComponentsConfiguration.threadPoolConfiguration;
@Nullable private List<ComponentLogParams> mInvalidStateLogParamsList;
Expand Down Expand Up @@ -83,6 +84,7 @@ private RecyclerBinderConfiguration(
boolean enableStableIds,
boolean enableItemPrefetch,
int itemViewCacheSize,
boolean requestMountForPrefetchedItems,
@Nullable RunnableHandler changeSetThreadHandler,
boolean isReconciliationEnabled,
boolean isLayoutDiffingEnabled,
Expand Down Expand Up @@ -112,6 +114,7 @@ private RecyclerBinderConfiguration(
mErrorEventHandler = errorEventHandler;
mEnableItemPrefetch = enableItemPrefetch;
mItemViewCacheSize = itemViewCacheSize;
mRequestMountForPrefetchedItems = requestMountForPrefetchedItems;
}

public float getRangeRatio() {
Expand Down Expand Up @@ -159,6 +162,10 @@ public int getItemViewCacheSize() {
return mItemViewCacheSize;
}

public boolean getRequestMountForPrefetchedItems() {
return mRequestMountForPrefetchedItems;
}

public @Nullable List<ComponentLogParams> getInvalidStateLogParamsList() {
return mInvalidStateLogParamsList;
}
Expand Down Expand Up @@ -217,6 +224,7 @@ public static class Builder {
private boolean mEnableStableIds = ComponentsConfiguration.enableRecyclerBinderStableId;
private boolean mEnableItemPrefetch = false;
private int mItemViewCacheSize = 0;
private boolean mRequestMountForPrefetchedItems = false;
private boolean mUseBackgroundChangeSets = SectionsConfiguration.useBackgroundChangeSets;
@Nullable private RunnableHandler mChangeSetThreadHandler;
private boolean mIsReconciliationEnabled = ComponentsConfiguration.isReconciliationEnabled;
Expand Down Expand Up @@ -252,6 +260,7 @@ private Builder(RecyclerBinderConfiguration configuration) {
this.mErrorEventHandler = configuration.mErrorEventHandler;
this.mEnableItemPrefetch = configuration.mEnableItemPrefetch;
this.mItemViewCacheSize = configuration.mItemViewCacheSize;
this.mRequestMountForPrefetchedItems = configuration.mRequestMountForPrefetchedItems;
}

/**
Expand Down Expand Up @@ -360,6 +369,15 @@ public Builder setItemViewCacheSize(int cacheSize) {
return this;
}

/**
* Experimental. See {@link RecyclerBinder.Builder#requestMountForPrefetchedItems(boolean)} for
* more info.
*/
public Builder setRequestMountForPrefetchedItems(boolean isEnabled) {
mRequestMountForPrefetchedItems = isEnabled;
return this;
}

public Builder componentsConfiguration(ComponentsConfiguration componentsConfiguration) {
this.mComponentsConfiguration = componentsConfiguration;
return this;
Expand Down Expand Up @@ -430,6 +448,7 @@ public RecyclerBinderConfiguration build() {
mEnableStableIds,
mEnableItemPrefetch,
mItemViewCacheSize,
mRequestMountForPrefetchedItems,
mChangeSetThreadHandler,
mIsReconciliationEnabled,
mIsLayoutDiffingEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ static void createInitialState(
.errorEventHandler(binderConfiguration.getErrorEventHandler())
.recyclerViewItemPrefetch(binderConfiguration.getEnableItemPrefetch())
.setItemViewCacheSize(binderConfiguration.getItemViewCacheSize())
.requestMountForPrefetchedItems(binderConfiguration.getRequestMountForPrefetchedItems())
.startupLogger(startupLogger);

if (binderConfiguration.getEstimatedViewportCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public class RecyclerBinder
private final boolean mIsLayoutDiffingEnabled;
private final boolean mRecyclerViewItemPrefetch;
private final int mItemViewCacheSize;
private final boolean mRequestMountForPrefetchedItems;
private final @RecyclingStrategy int mRecyclingStrategy;
private final @Nullable ErrorEventHandler mErrorEventHandler;
private final @Nullable ComponentsConfiguration mComponentsConfiguration;
Expand Down Expand Up @@ -479,6 +480,7 @@ public static class Builder {
private boolean visibilityProcessing = true;
private boolean acquireStateHandlerOnRelease = true;
private boolean recyclerViewItemPrefetch = false;
private boolean requestMountForPrefetchedItems = false;
private int itemViewCacheSize = 0;
private @RecyclingStrategy int recyclingStrategy =
ComponentsConfiguration.recyclerBinderStrategy;
Expand Down Expand Up @@ -616,6 +618,15 @@ public Builder setItemViewCacheSize(int size) {
return this;
}

/**
* Enable pre-mounting for pre-fetched items, which requires to turn on RecyclerView's item
* prefetching first. See {@link Builder#recyclerViewItemPrefetch(boolean) }.
*/
public Builder requestMountForPrefetchedItems(boolean isEnabled) {
this.requestMountForPrefetchedItems = isEnabled;
return this;
}

/**
* Do not enable this. This is an experimental feature and your Section surface will take a perf
* hit if you use it.
Expand Down Expand Up @@ -954,6 +965,7 @@ private RecyclerBinder(Builder builder) {
mLithoViewFactory = builder.lithoViewFactory;
mAcquireStateHandlerOnRelease = builder.acquireStateHandlerOnRelease;
mRecyclerViewItemPrefetch = builder.recyclerViewItemPrefetch;
mRequestMountForPrefetchedItems = builder.requestMountForPrefetchedItems;
mItemViewCacheSize = builder.itemViewCacheSize;
mComponentsConfiguration = builder.componentsConfiguration;

Expand Down Expand Up @@ -3936,7 +3948,7 @@ public void onPostDraw() {
mRecyclerBinderAdapterDelegate.onBindViewHolder(
holder, normalizedPosition, componentTreeHolder.getComponentTree(), renderInfo);

if (mComponentsConfiguration.requestMountForPrefetchedItems) {
if (mRequestMountForPrefetchedItems) {
// Try to pre-mount components marked as excludeFromIncrementalMount.
MountHelper.requestMount(componentTreeHolder.getComponentTree(), sEmptyRect, false);
}
Expand Down

0 comments on commit 5a58dfa

Please sign in to comment.