Is it possible to configure a LazyColumn/Row to al...
# compose
j
Is it possible to configure a LazyColumn/Row to always snap to discrete item positions after a scroll? It looks like this was possible previously with
FlingConfig
(now
FlingBehaviour
?) but I cant see how I can specify a list of anchors or snap points easily
a
https://google.github.io/accompanist/pager/ Is this what you are looking for?
j
@Albert Chang Yeah I experimented with this but it doesn’t emit page changes continuously. I opened an issue here https://github.com/google/accompanist/issues/313 but it seems this is more suited to swiping a single item at a time
p
@Jason Ankers if it’s just about the highlighting of the middle item you can do that without needing to get real-time updates of the selected position. I had a similar use-case (number wheel that repeats itself / infinite) and it works with the pager but is quite ugly since the fling is really slow as the pager tries to snap to every single item basically. You can use something like the following within the PagerScope:
Copy code
val absolutePageOffset =
          calculateCurrentOffsetForPage(position).absoluteValue.coerceIn(0f, 1f)
        val textColor = androidx.compose.ui.graphics.lerp(
            MaterialTheme.colors.primary.copy(alpha = ContentAlpha.medium),
            MaterialTheme.colors.primary,
            1 - absolutePageOffset
        )
j
@patrick Thanks that definitely helps with the highlighting. I think the main issue with using pager is we basically lose the scroll inertia so it feels a bit janky
p
Yup agreed https://github.com/google/accompanist/issues/257 could make it more easy to write our own fling behavior - but then again that’s not much fun either 😂