Sam
12/10/2020, 11:25 PMalpha08
, specifically lazyListState.smoothScrollBy
and lazyListState.snapToItemIndex
? We have a chat application so these new functions are critical for starting at the bottom of the message list, as well as revealing new messages into view as they arrive. However, the api is quite cumbersome for these reasons:
• snapToItemIndex
takes an index, but it’s not very easy to know how many items are in a LazyColumn
, because there could be group headers, arbitrary items etc and firstVisibleItemIndex
doesn’t help much
• snapToItemIndex
will only align the item to the top of the `LazyColumn`’s viewport, which is unhelpful in scenarios of scrolling to the very bottom of the list. There’s also scrollOffset
param but this requires every [variable height] item to be measured to calculate the offset, is this even possible?
• smoothScrollBy
seems to only take a relative offset, as you can imagine if 3 new messages come in within a chat interface, it’s a tough time to calculate everything needed to scroll to bottom, including the height of all new items as well as the current scroll position.
I know some might suggest using reverseScrollDirection
to avoid some of these challenges, but that leads to a bunch of tradeoffs down the line (e.g. maintaining scroll position when user is scrolled up, control over animation of new messages, infinite scroll older msgs, etc). Plus it’s not even available yet on LazyColumn
!Andrey Kulikov
12/10/2020, 11:59 PMalpha09
Sam
12/11/2020, 12:33 AMreverseScrollDirection
helps with some aspects of a chat interface while making other (less-obvious) things more difficult. I will try it out, but the questions still remain about the scroll apiTimo Drick
12/11/2020, 9:16 AMAndrey Kulikov
12/11/2020, 1:07 PMreverseScrollDirection
, but also reverseLayout
. this means that we layout item in reversed order as well. and when you will do snapToItemIndex(0) it will position the first item at the bottom. yes, please file a bug if you think that there is still something not covered after alpha09