Did anyone try to insert or remove 130 elements ah...
# compose
o
Did anyone try to insert or remove 130 elements ahead of visible elements into a
LazyColumn
or other lazy list? Spoiler: It does not work, the list loses track of its visible element positions.
😮 1
👀 1
A reproducer and suggested fix can be found in https://issuetracker.google.com/issues/273025639
m
Is they key unique and stable?
o
Yes, of course. The problem is a hard-coded sliding window in lazy layouts which remembers key-to-index mappings. If you insert a number of elements exceeding that window's size, the implementation fails to find the position. It then just stays at the previous visible elements' item indices, ignoring the actual shift of element positions. And it assumes that elements have been added/removed at the end of the list (instead of the beginning), moving the scrollbar in the wrong direction.
As you can see in the video, the right list always displays correctly, as it has a custom key-to-index map which does not suffer from the hard-coded limits. To fix this, I have mirrored the original implementations of
LazyColumn
and supporting code, adding an extra
keyToIndexMap
parameter. Both implementations in the video are driven by the exact same lists, keys and mappings.