What's the best way to know the scroll direction o...
# compose
d
What's the best way to know the scroll direction of a LazyColumn? I'm currently using a LazyListState, and by keeping a reference of the last value of
firstVisibleItemScrollOffset
from LazyListState, I can compare it to the current value so if
lastOffset
is lower than
firstVisibleItemScrollOffset
, that means the user is scrolling down, however if
lastOffset
is higher than
firstVisibleItemScrollOffset
, that means the user is scrolling up. At least that's the result I was hoping for but unfortunately
firstVisibleItemScrollOffset
is often equal to
lastOffset
. So what is the best way to know the scroll direction of a LazyColumn? 🤔 (What I would like to achieve is similar to what we used to do with the XML Toolbar View using app:layout_scrollFlags)
j
There was a snippet for this in the animation codelab, not sure if it's the best approach tho
a
there is no way to get this info from LazyListState unfortunately. I would suggest you to ask users of your composable to specify the layoutDirection manually
c
d
Thanks all of you. The solution from the codelab partially works because I'm using an animation. However it's not ideal also because I'm using an animation. Chris' solution partially works too. I have to mention that I created a component similar to ScaffoldLayout. So I created the nestedScrollCollection in that layout, and passed it as an argument to my "content" parameter. Unfortunately while scrolling slowly the animation on the top bar is choppy. I'm not entirely sure why though. (This would be a great component in one of Compose's libraries)
272 Views