Is there any chance to keep the scroll position wh...
# compose
a
Is there any chance to keep the scroll position when swapping the first visible item in an item keyed
LazyColumn
?
For example , if the list is scrolled to top and i swap the first item :
data[1] = data[0].also { data[0] = data[1] }
The scroll position should not anchored to data[0].
b
j
That sounds like the way to go. Compose leverages positional memoization which means if identifies composables based on the hash of the call but also its position in the sources. In lazy lists each item is traditionally called in the same line and that can create non unique keys. Providing an explicit key can likely help to maintain unique identities and probably help on that scrolling issue
a
I`m using item keys :
Copy code
LazyColumn(state = listState) {
    items(data, { it.id }) { item ->
This causes the issue , swapping without item keys keeps the position. But thats not really an option as swapping items without keys dosent really work :/