I have `LazyColumn` that I pass list of items into...
# compose
m
I have
LazyColumn
that I pass list of items into. I want to update items, new list with appended items, every second of so. when new items are received
LazyColumn
flickers and resets scroll to top. this happens even when I’m using
ImmutableList
and having item
key
defined. how can I append items without flicker and moving to top?
a
Does your code remember scroll state of LazyColumn?
m
yes it does. but even if that works there is flicker issue also
s
Are you using keys?
I'm blind, sorry.
😂 1
Can you paste a code snippet?
k
you need to override the
hashCode()
and
equals()
of the items that are getting diff'ed, which is what's causing the flicker I think, it's not just the keys.
Copy code
If these items are complex objects, properly implemented hashCode() and equals() methods help Compose efficiently identify changes
you need to help it identify content or instantiation differences
(one is a structural / partial difference, the other is difference in entire object itself )
this used to be a part of the
DiffUtil
process too
🙌 1
either that or your keys are not unique or not properly tied to the item's identity (key) (you need to make sure each item has a unique key and they're not all the same )
m
@Sean Proctor it’s pretty basic code. flow that emits new list with appended elements every second and the most basic
LazyColumn
you can imagine 😄
btw. nothing worked. keys are unique, overriding hash and equals didn’t do anything 🤷‍♂️
s
Can you make a small reproduction? It shouldn't flicker, so there's something specific about your code.
m
I will