I am trying to a selector that picks a card and sc...
# compose
g
I am trying to a selector that picks a card and scrolls a card at a time. Is there a way to get a ScrollableRow or HorizontalList to snap on each item. Recommendations appreciated!! This is close, but no snap:
Copy code
@Composable
private fun PagerLikeDemo() {
    val pages = listOf(Color.LightGray, Color.White, Color.DarkGray)
    LazyRowFor(pages) {
        Spacer(Modifier.fillParentMaxSize().background(it))
    }
}
z
I don't have a solid answer, but if you dig into the implementation of Slider, I believe there's an API related to fling features where you give it some anchor points and it will automatically snap to those. I think Slider uses it… or just look for any fling gesture stuff as a starting point.
😁 1
g
Thanks for all the help Zach. Much appreciated.
z
Sorry for being so vague 🙈
p
Have a look at Pager, which you can find in the Jetcaster sample. It uses fling to snap to a page. There is also an article related to this implementation:
Copy code
<https://jorgecastillo.dev/compose-viewpager>
1
👍 1
g
@Zach Klippenstein (he/him) [MOD] You take the time to respond to many of my questions. I wasn’t being mean. I seriously appreciate the help.
👍 1