Skip to content

Commit

Permalink
Use default value for stable ids if RecyclerBinder doesn't specify st…
Browse files Browse the repository at this point in the history
…able ids behavior

Summary:
We want to make the `stableIds` configuration to be controlled via the `ComponentsConfiguration` (so we can enable it in specific surfaces).

The first step is to make sure we get it from the current static value only if the client has not specified it on the `RecyclerBinderConfig`.

Differential Revision: D58729254

fbshipit-source-id: 84380fa26e004ea68ad827668927b59cb23c9133
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Jun 19, 2024
1 parent 8e7faf1 commit 1467f9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,20 @@ private RecyclerBinder(Builder builder) {
mParentLifecycle = builder.lifecycleProvider;

mComponentTreeHolderFactory = builder.componentTreeHolderFactory;

/*
This is a work-around to use the client explicit config, or if that hasn't happened to resort
to the one defined in the ComponentsConfiguration. We have to use this approach because atm the
[RecyclerBinderConfig] has an optional components configuration.
*/
boolean enableStableIdsToUse =
mRecyclerBinderConfig.enableStableIds != null
? mRecyclerBinderConfig.enableStableIds
: ComponentsConfiguration.defaultRecyclerBinderUseStableId;

// we cannot enable circular list and stable id at the same time
mEnableStableIds = (!mRecyclerBinderConfig.isCircular && mRecyclerBinderConfig.enableStableIds);
mEnableStableIds = (!mRecyclerBinderConfig.isCircular && enableStableIdsToUse);

mRecyclerBinderAdapterDelegate =
builder.adapterDelegate != null
? builder.adapterDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ data class RecyclerBinderConfig(
@JvmField val rangeRatio: Float = DEFAULT_RANGE_RATIO,
/**
* If set, the RecyclerView adapter will have stableId support turned on. Please note that this
* configuration will be disregarded in case [isCircular] is set to `true`.
* configuration will be disregarded in case [isCircular] is set to `true`. If not set, it will
* follow the default value set for the [ComponentsConfiguration]
*/
@JvmField
val enableStableIds: Boolean = ComponentsConfiguration.defaultRecyclerBinderUseStableId,
@JvmField val enableStableIds: Boolean? = null,
/**
* If true, the [RecyclerBinder] will measure the parent height by the height of children if the
* orientation is vertical, or measure the parent width by the width of children if the
Expand Down

0 comments on commit 1467f9b

Please sign in to comment.