Skip to content

Commit

Permalink
Add temporary support to enable stable ids on LazyLists
Browse files Browse the repository at this point in the history
Summary: We need to add the ability to enable stable ids for a `LazyList` surface in GenAI. Ideally, we would set this via `ComponentsConfiguration` (but it needs a bigger refactor fist). Therefore, I'm adding this ability to the `LazyList` signature temporarily while I work on the refactor.

Reviewed By: kingsleyadio

Differential Revision: D58684561

fbshipit-source-id: b67fcf90b5cb3487021086a2c7a7fc2492836097
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Jun 18, 2024
1 parent 0ab34b5 commit 8285aca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.annotation.Px
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.facebook.litho.ComponentContext
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.sections.widget.GridRecyclerConfiguration
import com.facebook.litho.sections.widget.ListRecyclerConfiguration
Expand Down Expand Up @@ -51,7 +52,8 @@ abstract class CollectionLayout(
val canMeasureRecycler: Boolean = false,
mainAxisWrapContent: Boolean = false,
preAllocationHandler: PreAllocationHandler?,
isCircular: Boolean
isCircular: Boolean,
enableStableIds: Boolean
) {
internal abstract fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder

Expand All @@ -71,7 +73,8 @@ abstract class CollectionLayout(
incrementalMountEnabled = isIncrementalMountEnabled),
rangeRatio = rangeRatio ?: RecyclerBinderConfig.DEFAULT_RANGE_RATIO,
wrapContent = mainAxisWrapContent,
isCircular = isCircular))
isCircular = isCircular,
enableStableIds = enableStableIds))
.useBackgroundChangeSets(useBackgroundChangeSets)
.build())
.build()
Expand Down Expand Up @@ -132,7 +135,8 @@ internal object CollectionLayouts {
crossAxisWrapMode: CrossAxisWrapMode = CrossAxisWrapMode.NoWrap,
mainAxisWrapContent: Boolean = false,
preAllocationHandler: PreAllocationHandler?,
isCircular: Boolean
isCircular: Boolean,
enableStableIds: Boolean
): CollectionLayout =
object :
CollectionLayout(
Expand All @@ -146,7 +150,8 @@ internal object CollectionLayouts {
canMeasureRecycler = crossAxisWrapMode.canMeasureRecycler,
mainAxisWrapContent = mainAxisWrapContent,
preAllocationHandler = preAllocationHandler,
isCircular = isCircular) {
isCircular = isCircular,
enableStableIds = enableStableIds) {
override fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder =
ListRecyclerConfiguration.create()
.snapMode(snapMode)
Expand Down Expand Up @@ -186,7 +191,8 @@ internal object CollectionLayouts {
useBackgroundChangeSets = useBackgroundChangeSets,
isReconciliationEnabled = isReconciliationEnabled,
preAllocationHandler = preAllocationHandler,
isCircular = false) {
isCircular = false,
enableStableIds = ComponentsConfiguration.defaultRecyclerBinderUseStableId) {
override fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder =
GridRecyclerConfiguration.create()
.snapMode(snapMode)
Expand Down Expand Up @@ -229,7 +235,8 @@ internal object CollectionLayouts {
isReconciliationEnabled = isReconciliationEnabled,
isIncrementalMountEnabled = isIncrementalMountEnabled,
preAllocationHandler = preAllocationHandler,
isCircular = false) {
isCircular = false,
enableStableIds = ComponentsConfiguration.defaultRecyclerBinderUseStableId) {
override fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder =
StaggeredGridRecyclerConfiguration.create().numSpans(spans).gapStrategy(gapStrategy)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.facebook.litho.Handle
import com.facebook.litho.LithoStartupLogger
import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.widget.LithoRecyclerView
import com.facebook.litho.widget.SnapUtil
Expand Down Expand Up @@ -75,6 +76,7 @@ inline fun ResourcesScope.LazyList(
fadingEdgeLength: Dimen? = null,
shouldExcludeFromIncrementalMount: Boolean = false,
isCircular: Boolean = false,
enableStableIds: Boolean = ComponentsConfiguration.defaultRecyclerBinderUseStableId,
init: LazyListScope.() -> Unit
): Component {
val lazyListScope = LazyListScope(context).apply { init() }
Expand All @@ -93,7 +95,8 @@ inline fun ResourcesScope.LazyList(
preAllocationHandler = preAllocationHandler,
crossAxisWrapMode = crossAxisWrapMode,
mainAxisWrapContent = mainAxisWrapContent,
isCircular = isCircular),
isCircular = isCircular,
enableStableIds = enableStableIds),
itemAnimator,
itemDecoration,
clipToPadding,
Expand Down

0 comments on commit 8285aca

Please sign in to comment.