Skip to content

Commit

Permalink
Expose layout factory for Lazy Collections
Browse files Browse the repository at this point in the history
Summary: We didn't expose layout factory for lazy collections which was reported by oncall request(https://fb.workplace.com/groups/litho.support/permalink/3906883812966291/), this diff is to expose it to all collections.

Reviewed By: zielinskimz

Differential Revision: D64706268

fbshipit-source-id: 2d0d415c43922c67df74c7edbf8d9e80347df96a
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Oct 22, 2024
1 parent bf59337 commit 8448097
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ private GridRecyclerConfiguration(
mRecyclerBinderConfiguration = recyclerBinderConfiguration;
mAllowMeasureOverride = allowMeasureOverride;
mGridLayoutInfoFactory =
gridLayoutInfoFactory == null
? GridRecyclerConfiguration.Builder.GRID_LAYOUT_INFO_FACTORY
: gridLayoutInfoFactory;
gridLayoutInfoFactory == null ? Builder.GRID_LAYOUT_INFO_FACTORY : gridLayoutInfoFactory;
mSnapMode = snapMode;
mSnapHelper = snapHelper;
}
Expand Down Expand Up @@ -142,7 +140,7 @@ public static final class Builder implements RecyclerConfiguration.Builder {
private boolean mAllowMeasureOverride = false;
private RecyclerBinderConfiguration mRecyclerBinderConfiguration =
RECYCLER_BINDER_CONFIGURATION;
private GridLayoutInfoFactory mGridLayoutInfoFactory = GRID_LAYOUT_INFO_FACTORY;
private @Nullable GridLayoutInfoFactory mGridLayoutInfoFactory;
private int mDeltaJumpThreshold = Integer.MAX_VALUE;
private int mSnapToStartFlingOffset = SnapUtil.SNAP_TO_START_DEFAULT_FLING_OFFSET;
private @SnapMode int mSnapMode = SNAP_NONE;
Expand Down Expand Up @@ -227,7 +225,7 @@ public Builder snapHelper(SnapHelper snapHelper) {
/**
* Provide a customized {@link GridLayoutInfo} through {@link GridLayoutInfoFactory} interface.
*/
public Builder gridLayoutInfoFactory(GridLayoutInfoFactory gridLayoutInfoFactory) {
public Builder gridLayoutInfoFactory(@Nullable GridLayoutInfoFactory gridLayoutInfoFactory) {
mGridLayoutInfoFactory = gridLayoutInfoFactory;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static final class Builder implements RecyclerConfiguration.Builder {
@SnapMode private int mSnapMode = SNAP_NONE;
private RecyclerBinderConfiguration mRecyclerBinderConfiguration =
RECYCLER_BINDER_CONFIGURATION;
private LinearLayoutInfoFactory mLinearLayoutInfoFactory = LINEAR_LAYOUT_INFO_FACTORY;
private @Nullable LinearLayoutInfoFactory mLinearLayoutInfoFactory;
private int mDeltaJumpThreshold = Integer.MAX_VALUE;
private int mSnapToStartFlingOffset = SnapUtil.SNAP_TO_START_DEFAULT_FLING_OFFSET;

Expand Down Expand Up @@ -194,7 +194,8 @@ public Builder recyclerBinderConfiguration(
return this;
}

public Builder linearLayoutInfoFactory(LinearLayoutInfoFactory linearLayoutInfoFactory) {
public Builder linearLayoutInfoFactory(
@Nullable LinearLayoutInfoFactory linearLayoutInfoFactory) {
mLinearLayoutInfoFactory = linearLayoutInfoFactory;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ private StaggeredGridRecyclerConfiguration(
boolean stackFromEnd,
int gapStrategy,
RecyclerBinderConfiguration recyclerBinderConfiguration,
StaggeredGridLayoutInfoFactory layoutInfoFactory) {
@Nullable StaggeredGridLayoutInfoFactory layoutInfoFactory) {
mNumSpans = numSpans;
mOrientation = orientation;
mReverseLayout = reverseLayout;
mStackFromEnd = stackFromEnd;
mGapStrategy = gapStrategy;
mRecyclerBinderConfiguration = recyclerBinderConfiguration;
mLayoutInfoFactory = layoutInfoFactory;
mLayoutInfoFactory =
layoutInfoFactory == null ? Builder.STAGGERED_GRID_LAYOUT_INFO_FACTORY : layoutInfoFactory;
}

@Override
Expand Down Expand Up @@ -125,7 +126,7 @@ public static final class Builder implements RecyclerConfiguration.Builder {
private int mGapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_NONE;
private RecyclerBinderConfiguration mRecyclerBinderConfiguration =
RECYCLER_BINDER_CONFIGURATION;
private StaggeredGridLayoutInfoFactory mLayoutInfoFactory = STAGGERED_GRID_LAYOUT_INFO_FACTORY;
private @Nullable StaggeredGridLayoutInfoFactory mLayoutInfoFactory;

Builder() {}

Expand Down Expand Up @@ -185,7 +186,7 @@ public Builder recyclerBinderConfiguration(
* StaggeredGridLayoutInfoFactory} interface.
*/
public Builder staggeredGridLayoutInfoFactory(
StaggeredGridLayoutInfoFactory staggeredGridLayoutInfoFactory) {
@Nullable StaggeredGridLayoutInfoFactory staggeredGridLayoutInfoFactory) {
mLayoutInfoFactory = staggeredGridLayoutInfoFactory;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.facebook.litho.ComponentContext
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.sections.widget.GridLayoutInfoFactory
import com.facebook.litho.sections.widget.GridRecyclerConfiguration
import com.facebook.litho.sections.widget.LinearLayoutInfoFactory
import com.facebook.litho.sections.widget.ListRecyclerConfiguration
import com.facebook.litho.sections.widget.RecyclerBinderConfiguration
import com.facebook.litho.sections.widget.RecyclerConfiguration
Expand Down Expand Up @@ -131,7 +133,8 @@ internal object CollectionLayouts {
mainAxisWrapContent: Boolean = false,
preAllocationHandler: PreAllocationHandler?,
isCircular: Boolean,
enableStableIds: Boolean
enableStableIds: Boolean,
linearLayoutInfoFactory: LinearLayoutInfoFactory?,
): CollectionLayout =
object :
CollectionLayout(
Expand All @@ -149,6 +152,7 @@ internal object CollectionLayouts {
override fun createRecyclerConfigurationBuilder(): RecyclerConfiguration.Builder =
ListRecyclerConfiguration.create()
.snapMode(snapMode)
.linearLayoutInfoFactory(linearLayoutInfoFactory)
.snapToStartOffset(snapToStartOffset)
}

Expand All @@ -175,6 +179,7 @@ internal object CollectionLayouts {
preAllocationHandler: PreAllocationHandler?,
enableStableIds: Boolean,
mainAxisWrapContent: Boolean = false,
gridLayoutInfoFactory: GridLayoutInfoFactory?,
): CollectionLayout =
object :
CollectionLayout(
Expand All @@ -192,6 +197,7 @@ internal object CollectionLayouts {
GridRecyclerConfiguration.create()
.snapMode(snapMode)
.snapToStartOffset(snapToStartOffset)
.gridLayoutInfoFactory(gridLayoutInfoFactory)
.numColumns(columns)
}

Expand All @@ -216,8 +222,7 @@ internal object CollectionLayouts {
isIncrementalMountEnabled: Boolean = true,
spans: Int = 2,
gapStrategy: Int = StaggeredGridLayoutManager.GAP_HANDLING_NONE,
staggeredGridlayoutInfoFactory: StaggeredGridLayoutInfoFactory =
StaggeredGridRecyclerConfiguration.Builder.STAGGERED_GRID_LAYOUT_INFO_FACTORY,
staggeredGridlayoutInfoFactory: StaggeredGridLayoutInfoFactory?,
preAllocationHandler: PreAllocationHandler?,
enableStableIds: Boolean
): CollectionLayout =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.facebook.litho.LithoStartupLogger
import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.sections.widget.GridLayoutInfoFactory
import com.facebook.litho.widget.LithoRecyclerView
import com.facebook.litho.widget.SnapUtil
import com.facebook.rendercore.Dimen
Expand Down Expand Up @@ -78,6 +79,7 @@ inline fun ResourcesScope.LazyGrid(
shouldExcludeFromIncrementalMount: Boolean = false,
enableStableIds: Boolean =
context.lithoConfiguration.componentsConfig.useStableIdsInRecyclerBinder,
gridLayoutInfoFactory: GridLayoutInfoFactory? = null,
crossinline init: LazyGridScope.() -> Unit
): Component {
val lazyGridScope = LazyGridScope(context).apply { init() }
Expand All @@ -95,6 +97,7 @@ inline fun ResourcesScope.LazyGrid(
columns = columns,
enableStableIds = enableStableIds,
mainAxisWrapContent = mainAxisWrapContent,
gridLayoutInfoFactory = gridLayoutInfoFactory,
),
itemAnimator,
itemDecoration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.facebook.litho.LithoStartupLogger
import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.sections.widget.LinearLayoutInfoFactory
import com.facebook.litho.widget.LithoRecyclerView
import com.facebook.litho.widget.SnapUtil
import com.facebook.rendercore.Dimen
Expand Down Expand Up @@ -79,6 +80,7 @@ inline fun ResourcesScope.LazyList(
isCircular: Boolean = false,
enableStableIds: Boolean =
context.lithoConfiguration.componentsConfig.useStableIdsInRecyclerBinder,
linearLayoutInfoFactory: LinearLayoutInfoFactory? = null,
crossinline init: LazyListScope.() -> Unit
): Component {
val lazyListScope = LazyListScope(context).apply { init() }
Expand All @@ -97,7 +99,9 @@ inline fun ResourcesScope.LazyList(
crossAxisWrapMode = crossAxisWrapMode,
mainAxisWrapContent = mainAxisWrapContent,
isCircular = isCircular,
enableStableIds = enableStableIds),
enableStableIds = enableStableIds,
linearLayoutInfoFactory = linearLayoutInfoFactory,
),
itemAnimator,
itemDecoration,
clipToPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.config.PreAllocationHandler
import com.facebook.litho.sections.widget.StaggeredGridLayoutInfoFactory
import com.facebook.litho.sections.widget.StaggeredGridRecyclerConfiguration
import com.facebook.litho.widget.LithoRecyclerView
import com.facebook.litho.widget.SnapUtil
import com.facebook.rendercore.Dimen
Expand Down Expand Up @@ -78,8 +77,7 @@ inline fun ResourcesScope.LazyStaggeredGrid(
preAllocationHandler: PreAllocationHandler? =
context.lithoConfiguration.componentsConfig.preAllocationHandler,
shouldExcludeFromIncrementalMount: Boolean = false,
staggeredGridlayoutInfoFactory: StaggeredGridLayoutInfoFactory =
StaggeredGridRecyclerConfiguration.Builder.STAGGERED_GRID_LAYOUT_INFO_FACTORY,
staggeredGridlayoutInfoFactory: StaggeredGridLayoutInfoFactory? = null,
enableStableIds: Boolean =
context.lithoConfiguration.componentsConfig.useStableIdsInRecyclerBinder,
crossinline init: LazyGridScope.() -> Unit
Expand Down

0 comments on commit 8448097

Please sign in to comment.