How To achieve HorizontalPager Velocity Based Scro...
# compose
s
How To achieve HorizontalPager Velocity Based Scrolling in accompanist pager? Context: I am using HorizontalPager and by default, it scrolls by 1 offset on a swipe. I want to implement a custom scroll, like if users swipes with a much larger velocity, then scroll accordingly like 5-6 cards ahead ... I saw FlingBehaviour is a parameter , but I wasn't able to understand on How to use it , any help will be appreciated and it would be gr8 if there is a sample / example showing such customization Is Fling Behaviour best suited ? OR can I disable Gestures/dragEnabled and Manually calculate scrollOffset using Modifier and then use animateScrollToPage (if this is the case , how to do this?) https://github.com/google/accompanist/discussions/529
c
What you've described isn't a pager, it's a
LazyRow
with some item snapping.
s
@cb I thought of that , and I realised I chose wrong holder and needed lazy row... but was just asking out of curiosity if its possible to do described in a pager somehow? blob thinking upside down
c
You could provide your own
FlingBehavior
which doesn’t stop at the nearest boundary. I haven’t tried it but it should work
s
I will dig into more , I wasnt able to grasp on how to actually use FlingBehaviour... anyway thanks for pointing it out so I know where to dig more👍
z
Hey, I'm also trying to find something like that.. It's a horizontal list.. if I swipe with a great velocity, it should scroll upto several items and when it's about to stop, the near to centre item have to snap to center automatically.. and if I swipe slowly, the next item should snap to center (this feels more like pager). Have you succeeded achieving this?
s
@Zeeshan Syed I used snapping behaviour with lazy row to achieve somewhat similar behaviour
z
@Shabinder Singh Can I have a sample code?
I am using a custom modified version of this
317 Views