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

orangy

06/12/2022, 1:03 PM
I have a
LazyColumn
and I want it to retain scroll position relative to the item key when I update the content. E.g. if I have items from the
listOf(1,2,3)
and I scroll to top, and then update data and repopulate items from
listOf(0,1,2,3)
I want scroll position to be still at item
1
with the same offset, and to see item
0
user would need to scroll up. Any hints on how to implement this effectively?
1
m

Marcin Wisniowski

06/12/2022, 2:13 PM
Interesting, I had that behavior by default, and had to figure out how to stop it from happening because I wanted it to be at 0 after the items change, but it stayed at 1.
z

Zoltan Demant

06/12/2022, 2:15 PM
I think that happens automatically if you specify keys for your items? I might be wrong 🤔
1
☝️ 1
o

orangy

06/12/2022, 3:23 PM
I did specify the keys, yes. Will need to investigate further…
👍🏽 1
Got it, I had “virtual” item at the top which would display “loading…” and it didn’t have a key, and it was always first, so it scrolled to it. Redesigned the component to have only real items in the list, and it all works
🦜 1
70 Views