Skip to content

Commit

Permalink
Migrate ComponentsConfiguration into RecyclerBinderConfig
Browse files Browse the repository at this point in the history
Summary: Migrate the `ComponentsConfiguration` from `RecyclerBinderConfiguration` and `RecyclerBinder.Builder` into the shared `RecyclerBinderConfig`

Reviewed By: adityasharat

Differential Revision: D52017065

fbshipit-source-id: b97fe551c56a3a96fc0d8a459367f4df164a1c18
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Dec 12, 2023
1 parent 1c2b372 commit 25f70dc
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +53,6 @@ private RecyclerBinderConfiguration(
RecyclerBinderConfig recyclerBinderConfig,
float rangeRatio,
@Nullable LayoutHandlerFactory layoutHandlerFactory,
@Nullable ComponentsConfiguration componentsConfiguration,
boolean wrapContent,
boolean useBackgroundChangeSets,
boolean enableStableIds,
Expand All @@ -69,7 +62,6 @@ private RecyclerBinderConfiguration(
boolean postToFrontOfQueueForFirstChangeset) {
mRangeRatio = rangeRatio;
mLayoutHandlerFactory = layoutHandlerFactory;
mComponentsConfiguration = componentsConfiguration;
mIsWrapContent = wrapContent;
mUseBackgroundChangeSets = useBackgroundChangeSets;
mEnableStableIds = enableStableIds;
Expand Down Expand Up @@ -116,10 +108,6 @@ public boolean isPostToFrontOfQueueForFirstChangeset() {
return mPostToFrontOfQueueForFirstChangeset;
}

public @Nullable ComponentsConfiguration getComponentsConfiguration() {
return mComponentsConfiguration;
}

public RecyclerBinderConfig getRecyclerBinderConfig() {
return mRecyclerBinderConfig;
}
Expand All @@ -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 =
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -258,7 +239,6 @@ public RecyclerBinderConfiguration build() {
: new RecyclerBinderConfig(),
mRangeRatio,
mLayoutHandlerFactory,
mComponentsConfiguration,
mWrapContent,
mUseBackgroundChangeSets,
mEnableStableIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ static void createInitialState(
.enableStableIds(binderConfiguration.getEnableStableIds())
.incrementalMount(incrementalMount && binderConfiguration.isIncrementalMountEnabled())
.stickyHeaderControllerFactory(stickyHeaderControllerFactory)
.componentsConfiguration(binderConfiguration.getComponentsConfiguration())
.isLayoutDiffingEnabled(binderConfiguration.isLayoutDiffingEnabled())
.startupLogger(startupLogger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ object CollectionRecyclerSpec {
layoutHandlerFactory(layoutHandlerFactory)
wrapContent(isWrapContent)
enableStableIds(enableStableIds)
componentsConfiguration(componentsConfiguration)
incrementalMount(isIncrementalMountEnabled)
isLayoutDiffingEnabled(isLayoutDiffingEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 25f70dc

Please sign in to comment.