Skip to content

Commit

Permalink
Add support for isIncrementalMountEnabled in LazyStaggeredGrid
Browse files Browse the repository at this point in the history
Summary: TSIA

Reviewed By: adityasharat

Differential Revision: D49659568

fbshipit-source-id: 0711537bfd18096de63ac3aec9d725822f780f7e
  • Loading branch information
mkarpio authored and facebook-github-bot committed Sep 28, 2023
1 parent 34ec258 commit cc857d7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class RecyclerBinderConfiguration {
ComponentsConfiguration.threadPoolConfiguration;
@Nullable private RunnableHandler mChangeSetThreadHandler;
private final boolean mIsReconciliationEnabled;
private final boolean mIsIncrementalMountEnabled;
private final boolean mIsLayoutDiffingEnabled;
private final boolean mPostToFrontOfQueueForFirstChangeset;
private final int mEstimatedViewportCount;
Expand Down Expand Up @@ -85,6 +86,7 @@ private RecyclerBinderConfiguration(
boolean requestMountForPrefetchedItems,
@Nullable RunnableHandler changeSetThreadHandler,
boolean isReconciliationEnabled,
boolean isIncrementalMountEnabled,
boolean isLayoutDiffingEnabled,
boolean postToFrontOfQueueForFirstChangeset,
@Nullable ComponentWarmer componentWarmer,
Expand All @@ -104,6 +106,7 @@ private RecyclerBinderConfiguration(
mEnableStableIds = enableStableIds;
mChangeSetThreadHandler = changeSetThreadHandler;
mIsReconciliationEnabled = isReconciliationEnabled;
mIsIncrementalMountEnabled = isIncrementalMountEnabled;
mIsLayoutDiffingEnabled = isLayoutDiffingEnabled;
mPostToFrontOfQueueForFirstChangeset = postToFrontOfQueueForFirstChangeset;
mComponentWarmer = componentWarmer;
Expand Down Expand Up @@ -177,6 +180,10 @@ public boolean isReconciliationEnabled() {
return mIsReconciliationEnabled;
}

public boolean isIncrementalMountEnabled() {
return mIsIncrementalMountEnabled;
}

public boolean isLayoutDiffingEnabled() {
return mIsLayoutDiffingEnabled;
}
Expand Down Expand Up @@ -226,6 +233,8 @@ public static class Builder {
private boolean mUseBackgroundChangeSets = SectionsConfiguration.useBackgroundChangeSets;
@Nullable private RunnableHandler mChangeSetThreadHandler;
private boolean mIsReconciliationEnabled = ComponentsConfiguration.isReconciliationEnabled;
private boolean mIsIncrementalMountEnabled =
!ComponentsConfiguration.isIncrementalMountGloballyDisabled;
private boolean mIsLayoutDiffingEnabled = ComponentsConfiguration.isLayoutDiffingEnabled;
private boolean mPostToFrontOfQueueForFirstChangeset;
private @Nullable ComponentWarmer mComponentWarmer;
Expand All @@ -249,6 +258,7 @@ private Builder(RecyclerBinderConfiguration configuration) {
this.mUseBackgroundChangeSets = configuration.mUseBackgroundChangeSets;
this.mChangeSetThreadHandler = configuration.mChangeSetThreadHandler;
this.mIsReconciliationEnabled = configuration.mIsReconciliationEnabled;
mIsIncrementalMountEnabled = configuration.mIsIncrementalMountEnabled;
this.mIsLayoutDiffingEnabled = configuration.mIsLayoutDiffingEnabled;
this.mPostToFrontOfQueueForFirstChangeset =
configuration.mPostToFrontOfQueueForFirstChangeset;
Expand Down Expand Up @@ -386,6 +396,15 @@ public Builder isReconciliationEnabled(boolean isEnabled) {
return this;
}

public Builder isIncrementalMountEnabled(boolean isEnabled) {
if (ComponentsConfiguration.isIncrementalMountGloballyDisabled) {
mIsIncrementalMountEnabled = false;
} else {
mIsIncrementalMountEnabled = isEnabled;
}
return this;
}

public Builder isLayoutDiffingEnabled(boolean isEnabled) {
mIsLayoutDiffingEnabled = isEnabled;
return this;
Expand Down Expand Up @@ -453,6 +472,7 @@ public RecyclerBinderConfiguration build() {
mRequestMountForPrefetchedItems,
mChangeSetThreadHandler,
mIsReconciliationEnabled,
mIsIncrementalMountEnabled,
mIsLayoutDiffingEnabled,
mPostToFrontOfQueueForFirstChangeset,
mComponentWarmer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static void createInitialState(
.hscrollAsyncMode(binderConfiguration.getHScrollAsyncMode())
.isCircular(binderConfiguration.isCircular())
.hasDynamicItemHeight(binderConfiguration.hasDynamicItemHeight())
.incrementalMount(incrementalMount)
.incrementalMount(incrementalMount && binderConfiguration.isIncrementalMountEnabled())
.stickyHeaderControllerFactory(stickyHeaderControllerFactory)
.componentsConfiguration(binderConfiguration.getComponentsConfiguration())
.isReconciliationEnabled(binderConfiguration.isReconciliationEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.facebook.litho.widget.collection
import androidx.annotation.Px
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.sections.widget.GridRecyclerConfiguration
import com.facebook.litho.sections.widget.ListRecyclerConfiguration
import com.facebook.litho.sections.widget.RecyclerBinderConfiguration
Expand All @@ -40,6 +41,8 @@ abstract class CollectionLayout(
rangeRatio: Float? = null,
useBackgroundChangeSets: Boolean = false,
isReconciliationEnabled: Boolean = false,
isIncrementalMountEnabled: Boolean =
!ComponentsConfiguration.isIncrementalMountGloballyDisabled,
hasDynamicItemHeight: Boolean = false,
val canMeasureRecycler: Boolean = false,
mainAxisWrapContent: Boolean = false,
Expand All @@ -62,6 +65,7 @@ abstract class CollectionLayout(
.wrapContent(mainAxisWrapContent)
.useBackgroundChangeSets(useBackgroundChangeSets)
.isReconciliationEnabled(isReconciliationEnabled)
.isIncrementalMountEnabled(isIncrementalMountEnabled)
.shouldPreallocatePerMountContent(preallocationPerMountContentEnabled)
.build())
.build()
Expand Down Expand Up @@ -193,6 +197,7 @@ internal object CollectionLayouts {
rangeRatio: Float? = null,
useBackgroundChangeSets: Boolean = false,
isReconciliationEnabled: Boolean = false,
isIncrementalMountEnabled: Boolean = true,
spans: Int = 2,
gapStrategy: Int = StaggeredGridLayoutManager.GAP_HANDLING_NONE,
preallocationPerMountContentEnabled: Boolean,
Expand All @@ -204,6 +209,7 @@ internal object CollectionLayouts {
rangeRatio = rangeRatio,
useBackgroundChangeSets = useBackgroundChangeSets,
isReconciliationEnabled = isReconciliationEnabled,
isIncrementalMountEnabled = isIncrementalMountEnabled,
preallocationPerMountContentEnabled = preallocationPerMountContentEnabled,
) {
override fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ object CollectionRecyclerSpec {
hasDynamicItemHeight(hasDynamicItemHeight())
componentsConfiguration(componentsConfiguration)
isReconciliationEnabled(isReconciliationEnabled)
incrementalMount(isIncrementalMountEnabled)
isLayoutDiffingEnabled(isLayoutDiffingEnabled)
componentWarmer(componentWarmer)
lithoViewFactory(lithoViewFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ inline fun ResourcesScope.LazyStaggeredGrid(
rangeRatio: Float? = null,
useBackgroundChangeSets: Boolean = false,
isReconciliationEnabled: Boolean = false,
isIncrementalMountEnabled: Boolean = true,
childEquivalenceIncludesCommonProps: Boolean = true,
overlayRenderCount: Boolean = false,
alwaysDetectDuplicates: Boolean = false,
Expand All @@ -82,6 +83,7 @@ inline fun ResourcesScope.LazyStaggeredGrid(
rangeRatio = rangeRatio,
useBackgroundChangeSets = useBackgroundChangeSets,
isReconciliationEnabled = isReconciliationEnabled,
isIncrementalMountEnabled = isIncrementalMountEnabled,
preallocationPerMountContentEnabled = preallocationPerMountContentEnabled,
spans = spans,
gapStrategy = gapStrategy),
Expand Down

0 comments on commit cc857d7

Please sign in to comment.