ste
10/20/2022, 4:00 PMSnapLayoutInfoProvider
for a ScrollState
(used by a Pager
composable, where all the items have fillMaxSize
), but I don't really get what calculateSnappingOffsetBounds
is expected to return. I don't understand the doc either.
I mean, shouldn't an offset be enough (i.e. the new `ScrollState`'s value
)?jossiwolf
10/20/2022, 4:40 PMste
10/20/2022, 4:42 PM@ExperimentalFoundationApi
fun SnapLayoutInfoProvider(
itemCount: Int,
scrollState: ScrollState,
): SnapLayoutInfoProvider = object : SnapLayoutInfoProvider {
override fun Density.calculateApproachOffset(initialVelocity: Float): Float = 0f
override fun Density.calculateSnappingOffsetBounds(): ClosedFloatingPointRange<Float> {
val bound0 = -scrollState.value % snapStepSize()
val bound1 = snapStepSize() + bound0
return (if (bound0 >= 0 && bound1 < 0) bound1.rangeTo(bound0) else bound0.rangeTo(bound1))
}
override fun Density.snapStepSize(): Float = scrollState.maxValue.toFloat() / (itemCount - 1)
}
levima
10/20/2022, 4:50 PMste
10/20/2022, 4:53 PM