https://kotlinlang.org logo
#compose
Title
# compose
g

Guy Bieber

10/08/2020, 9:07 PM
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

Zach Klippenstein (he/him) [MOD]

10/08/2020, 10:16 PM
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

Guy Bieber

10/08/2020, 10:17 PM
Thanks for all the help Zach. Much appreciated.
z

Zach Klippenstein (he/him) [MOD]

10/08/2020, 10:21 PM
Sorry for being so vague 🙈
p

Photoxor

10/08/2020, 11:05 PM
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

Guy Bieber

10/08/2020, 11:07 PM
@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