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

Archie

08/02/2020, 12:45 PM
Is there a way to add Snapping behavior for
Horizontal Scroller
just like how
ViewPager
snaps per page?
h

Halil Ozercan

08/02/2020, 2:27 PM
I'm on mobile so I can't find the exact class but Jetpack Compose Playground app should have an example that implements this behavior
a

Archie

08/02/2020, 3:35 PM
It seems that theres alot of examples there. Do you know which one I should look into?
z

Zach Klippenstein (he/him) [MOD]

08/02/2020, 4:04 PM
I think there's some Fling-related stuff that does snapping. Maybe FlingConfig?
f

Foso

08/02/2020, 4:16 PM
Take a look at SpringBackScrollingDemo . zachklipp is right, there is a fling() for an AnimatedFloat and a animateTo(). https://github.com/Foso/Jetpack-Compose-Playground/blob/master/compose/src/main/java/androidx/compose/animation/SpringBackScrollingDemo.kt
a

Archie

08/02/2020, 5:58 PM
@Foso does this mean I have ditch
ScrollableRow
all together? And handle the scrolling by myself?
f

Foso

08/02/2020, 6:06 PM
I don't know, i haven't seen an compose equivalent of a viewpager yet. I think you have to build yourself, or maybe this is working: https://github.com/vanpra/ComposeViewPager
9 Views