Skip to content

Commit

Permalink
enable center snapping for font picker
Browse files Browse the repository at this point in the history
Summary:
This diff:
1. Adds custom snap helper support to the LazyList litho component
2. Adds a custom snap helper for the text tool font helper that snaps elements to the center of the screen. This was previously broken such that first and last element couldnt be selected.

Reviewed By: astreet

Differential Revision: D66485165

fbshipit-source-id: 1d765dde730424db7d0db6f5a13723b31e66c8c5
  • Loading branch information
Shahzeb Mustafa authored and facebook-github-bot committed Dec 10, 2024
1 parent 3145757 commit 6f417c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.facebook.litho.widget.collection

import androidx.annotation.Px
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.facebook.litho.ComponentContext
import com.facebook.litho.config.PreAllocationHandler
Expand Down Expand Up @@ -114,6 +115,7 @@ internal object CollectionLayouts {
isCircular: Boolean,
enableStableIds: Boolean,
linearLayoutInfoFactory: LinearLayoutInfoFactory?,
snapHelper: SnapHelper?,
): CollectionLayout =
object :
CollectionLayout(
Expand All @@ -132,6 +134,11 @@ internal object CollectionLayouts {
.snapMode(snapMode)
.linearLayoutInfoFactory(linearLayoutInfoFactory)
.snapToStartOffset(snapToStartOffset)
.also {
if (snapHelper != null) {
it.snapHelper(snapHelper)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.facebook.litho.widget.collection

import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
import com.facebook.litho.Component
import com.facebook.litho.Handle
import com.facebook.litho.LithoStartupLogger
Expand All @@ -36,6 +37,7 @@ import com.facebook.rendercore.dp
inline fun ResourcesScope.LazyList(
@RecyclerView.Orientation orientation: Int = RecyclerView.VERTICAL,
@SnapUtil.SnapMode snapMode: Int = SnapUtil.SNAP_NONE,
snapHelper: SnapHelper? = null,
snapToStartOffset: Dimen = 0.dp,
reverse: Boolean = false,
crossAxisWrapMode: CrossAxisWrapMode = CrossAxisWrapMode.NoWrap,
Expand Down Expand Up @@ -95,6 +97,7 @@ inline fun ResourcesScope.LazyList(
componentContext = context,
orientation = orientation,
snapMode = snapMode,
snapHelper = snapHelper,
snapToStartOffset = snapToStartOffset.toPixels(resourceResolver),
reverse = reverse,
rangeRatio = rangeRatio,
Expand Down

0 comments on commit 6f417c9

Please sign in to comment.