Skip to content

Commit

Permalink
Add new binding strategy for Experimental Recycler
Browse files Browse the repository at this point in the history
Summary: As we are seeing video related regression in the *Split Binders* approach, I'm adding a new one that replicates the *Recycler Spec* one, only extracting the item decoration into a separate binder. This is to clear off that the issue could be with the item decorations binder or not.

Reviewed By: apowolny

Differential Revision: D60131045

fbshipit-source-id: 7f940996fb1dad8c88ea571960e8445103ae5d06
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Jul 26, 2024
1 parent 3db73e5 commit 360e5b8
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ enum class PrimitiveRecyclerBinderStrategy {
* @see [com.facebook.litho.widget.ExperimentalRecycler.SplitBindersMountBehavior]
*/
SPLIT_BINDERS,

/** In this strategy we only remove the item decoration binding from the original approach. */
RECYCLER_SPEC_EQUIVALENT_AND_ITEM_DECORATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class ExperimentalRecycler(
measureVersion, onRefresh, onScrollListeners, recyclerEventsController)
PrimitiveRecyclerBinderStrategy.SPLIT_BINDERS ->
SplitBindersMountBehavior(onRefresh, onScrollListeners, recyclerEventsController)
PrimitiveRecyclerBinderStrategy.RECYCLER_SPEC_EQUIVALENT_AND_ITEM_DECORATION ->
RecyclerSpecEquivalentAndItemDecorationMountBehavior(
measureVersion, onRefresh, onScrollListeners, recyclerEventsController)
}

return LithoPrimitive(
Expand Down Expand Up @@ -221,6 +224,109 @@ class ExperimentalRecycler(
}
}

private fun PrimitiveComponentScope.RecyclerSpecEquivalentAndItemDecorationMountBehavior(
measureVersion: State<Int>,
onRefresh: (() -> Unit)?,
onScrollListeners: List<RecyclerView.OnScrollListener>?,
recyclerEventsController: RecyclerEventsController?
): MountBehavior<SectionsRecyclerView> =
MountBehavior(
ViewAllocator { context -> SectionsRecyclerView(context, LithoRecyclerView(context)) }) {
doesMountRenderTreeHosts = true
shouldExcludeFromIncrementalMount = excludeFromIncrementalMount

withDescription("recycler-decorations") {
bind(itemDecorations) { sectionsRecyclerView ->
val recyclerView = sectionsRecyclerView.requireLithoRecyclerView()

itemDecorations?.forEach(recyclerView::addItemDecoration)

onUnbind { itemDecorations?.forEach(recyclerView::removeItemDecoration) }
}
}

// RecyclerSpec's @OnMount and @OnUnmount
withDescription("recycler-equivalent-mount") {
bind(
measureVersion.value,
binder,
hasFixedSize,
isClipToPaddingEnabled,
leftPadding,
topPadding,
rightPadding,
bottomPadding,
isClipChildrenEnabled,
scrollBarStyle,
isHorizontalFadingEdgeEnabled,
isVerticalFadingEdgeEnabled,
fadingEdgeLength,
refreshProgressBarBackgroundColor,
refreshProgressBarColor,
itemAnimator?.javaClass) { sectionsRecyclerView ->
val recyclerView = sectionsRecyclerView.requireLithoRecyclerView()

bindLegacyMountBinder(
sectionsRecyclerView = sectionsRecyclerView,
contentDescription = contentDescription,
hasFixedSize = hasFixedSize,
isClipToPaddingEnabled = isClipToPaddingEnabled,
paddingAdditionDisabled = paddingAdditionDisabled,
leftPadding = leftPadding,
topPadding = topPadding,
rightPadding = rightPadding,
bottomPadding = bottomPadding,
isClipChildrenEnabled = isClipChildrenEnabled,
isNestedScrollingEnabled = isNestedScrollingEnabled,
scrollBarStyle = scrollBarStyle,
isHorizontalFadingEdgeEnabled = isHorizontalFadingEdgeEnabled,
isVerticalFadingEdgeEnabled = isVerticalFadingEdgeEnabled,
fadingEdgeLength = fadingEdgeLength,
recyclerViewId = recyclerViewId,
overScrollMode = overScrollMode,
edgeFactory = edgeFactory,
refreshProgressBarBackgroundColor = refreshProgressBarBackgroundColor,
refreshProgressBarColor = refreshProgressBarColor,
itemAnimator = itemAnimator)

binder.mount(recyclerView)

onUnbind {
unbindLegacyMountBinder(
sectionsRecyclerView = sectionsRecyclerView,
refreshProgressBarBackgroundColor = refreshProgressBarBackgroundColor,
edgeFactory = edgeFactory,
snapHelper = snapHelper)

binder.unmount(recyclerView)
}
}
}

withDescription("recycler-equivalent-bind") {
bind(Any()) { sectionsRecyclerView ->
bindLegacyAttachBinder(
sectionsRecyclerView = sectionsRecyclerView,
sectionsViewLogger = sectionsViewLogger,
isPullToRefreshEnabled = isPullToRefreshEnabled,
onRefresh = onRefresh,
onScrollListeners = onScrollListeners,
touchInterceptor = touchInterceptor,
onItemTouchListener = onItemTouchListener,
snapHelper = snapHelper,
recyclerEventsController = recyclerEventsController)

onUnbind {
unbindLegacyAttachBinder(
sectionsRecyclerView = sectionsRecyclerView,
recyclerEventsController = recyclerEventsController,
onScrollListeners = onScrollListeners,
onItemTouchListener = onItemTouchListener)
}
}
}
}

/**
* This is one [MountBehavior<SectionsRecyclerView>] that uses three different binders to mount
* the content.
Expand Down

0 comments on commit 360e5b8

Please sign in to comment.