From 25f70dc00766c0b92cb5753b389822206702c860 Mon Sep 17 00:00:00 2001 From: Fabio Carballo Date: Tue, 12 Dec 2023 06:06:06 -0800 Subject: [PATCH] Migrate ComponentsConfiguration into RecyclerBinderConfig Summary: Migrate the `ComponentsConfiguration` from `RecyclerBinderConfiguration` and `RecyclerBinder.Builder` into the shared `RecyclerBinderConfig` Reviewed By: adityasharat Differential Revision: D52017065 fbshipit-source-id: b97fe551c56a3a96fc0d8a459367f4df164a1c18 --- .../litho/ComponentsConfigurationTest.kt | 11 ++++++++-- .../litho/widget/ComponentWarmerTest.java | 11 ++++++---- .../widget/RecyclerBinderConfiguration.java | 20 ------------------- .../RecyclerCollectionComponentSpec.java | 1 - ...rimentalRecyclerCollectionComponentSpec.kt | 1 - .../collection/CollectionRecyclerSpec.kt | 1 - .../facebook/litho/widget/RecyclerBinder.java | 8 +------- .../litho/widget/RecyclerBinderConfig.kt | 14 +++++++++++++ 8 files changed, 31 insertions(+), 36 deletions(-) diff --git a/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt b/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt index ceb829c1de6..3e8e7a86d3c 100644 --- a/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt +++ b/litho-it/src/test/java/com/facebook/litho/ComponentsConfigurationTest.kt @@ -27,6 +27,7 @@ import com.facebook.litho.sections.widget.RecyclerBinderConfiguration import com.facebook.litho.sections.widget.RecyclerCollectionComponent import com.facebook.litho.testing.LegacyLithoViewRule import com.facebook.litho.testing.testrunner.LithoTestRunner +import com.facebook.litho.widget.RecyclerBinderConfig import org.assertj.core.api.Assertions.assertThat import org.junit.Rule import org.junit.Test @@ -61,11 +62,17 @@ class ComponentsConfigurationTest { @Test fun testSetFlagThroughComponentConfigToComponentTreeWithRecyclerCollectionComponent() { ComponentsConfiguration.defaultInstance = - defaultConfiguration.copy(useCancellableLayoutFutures = true) + defaultConfiguration.copy(useCancellableLayoutFutures = false) + val recyclerBinderConfiguration = RecyclerBinderConfiguration.create() - .componentsConfiguration(ComponentsConfiguration.defaultInstance) + .recyclerBinderConfig( + RecyclerBinderConfig( + componentsConfiguration = + ComponentsConfiguration.defaultInstance.copy( + useCancellableLayoutFutures = true))) .build() + legacyLithoViewRule .setRoot( RecyclerCollectionComponent.create(componentContext) diff --git a/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java b/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java index df0f80bdba3..a9018953356 100644 --- a/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java +++ b/litho-it/src/test/java/com/facebook/litho/widget/ComponentWarmerTest.java @@ -149,11 +149,11 @@ public void testPrepareAsyncForRecyclerBinder() { public void testCancelDuringPrepareAsync() { final RecyclerBinder binder = new RecyclerBinder.Builder() - .componentsConfiguration( - ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) .recyclerBinderConfig( RecyclerBinderConfig.create() .threadPoolConfig(new LayoutThreadPoolConfigurationImpl(2, 2, 5)) + .componentsConfiguration( + ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) .build()) .build(mContext); @@ -222,8 +222,11 @@ protected Component onCreateLayout(ComponentContext c) { public void testCancelDuringPrepare() { final RecyclerBinder binder = new RecyclerBinder.Builder() - .componentsConfiguration( - ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) + .recyclerBinderConfig( + RecyclerBinderConfig.create() + .componentsConfiguration( + ComponentsConfiguration.create().useCancellableLayoutFutures(true).build()) + .build()) .build(mContext); binder.measure( diff --git a/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerBinderConfiguration.java b/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerBinderConfiguration.java index 1e2ff869122..241e70a6f6d 100644 --- a/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerBinderConfiguration.java +++ b/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerBinderConfiguration.java @@ -28,12 +28,6 @@ /** Configuration setting for {@link RecyclerBinder}. */ public class RecyclerBinderConfiguration { - /** - * Used to pass through configuration flags to the componentTree that can be read directly from - * this componentsConfiguration instance. - */ - private final @Nullable ComponentsConfiguration mComponentsConfiguration; - private final float mRangeRatio; @Nullable private final LayoutHandlerFactory mLayoutHandlerFactory; private final boolean mIsWrapContent; @@ -59,7 +53,6 @@ private RecyclerBinderConfiguration( RecyclerBinderConfig recyclerBinderConfig, float rangeRatio, @Nullable LayoutHandlerFactory layoutHandlerFactory, - @Nullable ComponentsConfiguration componentsConfiguration, boolean wrapContent, boolean useBackgroundChangeSets, boolean enableStableIds, @@ -69,7 +62,6 @@ private RecyclerBinderConfiguration( boolean postToFrontOfQueueForFirstChangeset) { mRangeRatio = rangeRatio; mLayoutHandlerFactory = layoutHandlerFactory; - mComponentsConfiguration = componentsConfiguration; mIsWrapContent = wrapContent; mUseBackgroundChangeSets = useBackgroundChangeSets; mEnableStableIds = enableStableIds; @@ -116,10 +108,6 @@ public boolean isPostToFrontOfQueueForFirstChangeset() { return mPostToFrontOfQueueForFirstChangeset; } - public @Nullable ComponentsConfiguration getComponentsConfiguration() { - return mComponentsConfiguration; - } - public RecyclerBinderConfig getRecyclerBinderConfig() { return mRecyclerBinderConfig; } @@ -131,7 +119,6 @@ public static class Builder { private RecyclerBinderConfig mRecyclerBinderConfig; @Nullable private LayoutHandlerFactory mLayoutHandlerFactory; - private @Nullable ComponentsConfiguration mComponentsConfiguration; private float mRangeRatio = DEFAULT_RANGE; private boolean mWrapContent = false; private boolean mEnableStableIds = @@ -148,7 +135,6 @@ public static class Builder { private Builder(RecyclerBinderConfiguration configuration) { mRecyclerBinderConfig = configuration.mRecyclerBinderConfig; this.mLayoutHandlerFactory = configuration.mLayoutHandlerFactory; - this.mComponentsConfiguration = configuration.mComponentsConfiguration; this.mRangeRatio = configuration.mRangeRatio; this.mWrapContent = configuration.mIsWrapContent; this.mEnableStableIds = configuration.mEnableStableIds; @@ -219,11 +205,6 @@ public Builder enableStableIds(boolean enableStableIds) { return this; } - public Builder componentsConfiguration(ComponentsConfiguration componentsConfiguration) { - this.mComponentsConfiguration = componentsConfiguration; - return this; - } - public Builder changeSetThreadHandler(@Nullable RunnableHandler changeSetThreadHandler) { mChangeSetThreadHandler = changeSetThreadHandler; return this; @@ -258,7 +239,6 @@ public RecyclerBinderConfiguration build() { : new RecyclerBinderConfig(), mRangeRatio, mLayoutHandlerFactory, - mComponentsConfiguration, mWrapContent, mUseBackgroundChangeSets, mEnableStableIds, diff --git a/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerCollectionComponentSpec.java b/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerCollectionComponentSpec.java index 0440e2c964c..c85024a6d30 100644 --- a/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerCollectionComponentSpec.java +++ b/litho-sections-widget/src/main/java/com/facebook/litho/sections/widget/RecyclerCollectionComponentSpec.java @@ -323,7 +323,6 @@ static void createInitialState( .enableStableIds(binderConfiguration.getEnableStableIds()) .incrementalMount(incrementalMount && binderConfiguration.isIncrementalMountEnabled()) .stickyHeaderControllerFactory(stickyHeaderControllerFactory) - .componentsConfiguration(binderConfiguration.getComponentsConfiguration()) .isLayoutDiffingEnabled(binderConfiguration.isLayoutDiffingEnabled()) .startupLogger(startupLogger); diff --git a/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/kotlin/widget/ExperimentalRecyclerCollectionComponentSpec.kt b/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/kotlin/widget/ExperimentalRecyclerCollectionComponentSpec.kt index e3aea572526..47c96c651eb 100644 --- a/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/kotlin/widget/ExperimentalRecyclerCollectionComponentSpec.kt +++ b/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/kotlin/widget/ExperimentalRecyclerCollectionComponentSpec.kt @@ -300,7 +300,6 @@ object ExperimentalRecyclerCollectionComponentSpec { .enableStableIds(binderConfiguration.enableStableIds) .incrementalMount(incrementalMount) .stickyHeaderControllerFactory(stickyHeaderControllerFactory) - .componentsConfiguration(binderConfiguration.componentsConfiguration) .isLayoutDiffingEnabled(binderConfiguration.isLayoutDiffingEnabled) .startupLogger(startupLogger) val recyclerBinder = recyclerBinderBuilder.build(c) diff --git a/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/widget/collection/CollectionRecyclerSpec.kt b/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/widget/collection/CollectionRecyclerSpec.kt index 2756fc73c12..5d9eaec4b07 100644 --- a/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/widget/collection/CollectionRecyclerSpec.kt +++ b/litho-widget-kotlin/src/main/kotlin/com/facebook/litho/widget/collection/CollectionRecyclerSpec.kt @@ -154,7 +154,6 @@ object CollectionRecyclerSpec { layoutHandlerFactory(layoutHandlerFactory) wrapContent(isWrapContent) enableStableIds(enableStableIds) - componentsConfiguration(componentsConfiguration) incrementalMount(isIncrementalMountEnabled) isLayoutDiffingEnabled(isLayoutDiffingEnabled) } diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java index 5a03aba49f5..83cd6362f5f 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java @@ -457,7 +457,6 @@ public static class Builder { private RecyclerBinderConfig mRecyclerBinderConfig; private float rangeRatio = DEFAULT_RANGE_RATIO; private LayoutInfo layoutInfo; - private @Nullable ComponentsConfiguration componentsConfiguration; private @Nullable LayoutHandlerFactory layoutHandlerFactory; private ComponentTreeHolderFactory componentTreeHolderFactory = DEFAULT_COMPONENT_TREE_HOLDER_FACTORY; @@ -524,11 +523,6 @@ public Builder layoutInfo(LayoutInfo layoutInfo) { return this; } - public Builder componentsConfiguration(@Nullable ComponentsConfiguration config) { - this.componentsConfiguration = config; - return this; - } - /** * @param layoutHandlerFactory the RecyclerBinder will use this layoutHandlerFactory when * creating {@link ComponentTree}s in order to specify on which thread layout calculation @@ -814,7 +808,7 @@ private RecyclerBinder(Builder builder) { mRecyclerViewItemPrefetch = mRecyclerBinderConfig.recyclerViewItemPrefetch; mRequestMountForPrefetchedItems = mRecyclerBinderConfig.requestMountForPrefetchedItems; mItemViewCacheSize = mRecyclerBinderConfig.itemViewCacheSize; - mComponentsConfiguration = builder.componentsConfiguration; + mComponentsConfiguration = mRecyclerBinderConfig.componentsConfiguration; if (mLayoutHandlerFactory == null && mRecyclerBinderConfig.threadPoolConfig != null) { mThreadPoolConfig = mRecyclerBinderConfig.threadPoolConfig; diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinderConfig.kt b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinderConfig.kt index 87dba0ed45b..950bef22de2 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinderConfig.kt +++ b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinderConfig.kt @@ -32,6 +32,14 @@ import com.facebook.rendercore.RunnableHandler */ @DataClassGenerate(toString = Mode.OMIT, equalsHashCode = Mode.KEEP) data class RecyclerBinderConfig( + /** + * Defines if an overriding [com.facebook.litho.config.ComponentsConfiguration] should be used + * in the [com.facebook.litho.ComponentTree] used in the [RecyclerBinder] hierarchy. + * + * If [null], then it will attempt to use the one associated with the + * [com.facebook.litho.ComponentContext] used to create the [RecyclerBinder]. + */ + @JvmField val componentsConfiguration: ComponentsConfiguration? = null, /** * Whether the underlying RecyclerBinder will have a circular behaviour. Defaults to false. * Note: circular lists DO NOT support any operation that changes the size of items like insert, @@ -181,6 +189,7 @@ class RecyclerBinderConfigBuilder internal constructor(configuration: RecyclerBi private var reconciliationEnabled = configuration.reconciliationEnabled private var preallocateMountContent = configuration.preallocateMountContent private var preallocateMountContentHandler = configuration.preallocateMountContentHandler + private var componentsConfiguration = configuration.componentsConfiguration fun isCircular(isCircular: Boolean): RecyclerBinderConfigBuilder = also { this.isCircular = isCircular @@ -239,8 +248,13 @@ class RecyclerBinderConfigBuilder internal constructor(configuration: RecyclerBi preallocateMountContentHandler = handler } + fun componentsConfiguration( + componentsConfiguration: ComponentsConfiguration? + ): RecyclerBinderConfigBuilder = also { this.componentsConfiguration = componentsConfiguration } + fun build(): RecyclerBinderConfig { return RecyclerBinderConfig( + componentsConfiguration = componentsConfiguration, isCircular = isCircular, lithoViewFactory = lithoViewFactory, hScrollAsyncMode = hScrollAsyncMode,