Is there an annotation in compose that says “pleas...
# compose
a
Is there an annotation in compose that says “please don’t remember me”
🚫 1
z
You could implement RememberObserver and throw 😈
lol 4
☝🏾 1
💯 1
s
I really wanna know why you want that though 😄
a
Well in compose you can’t have lazy layout items with same key. However we often get them in our app due to how we get products, flatten their contents into a single lazy column, sometimes there’s duplicate products or items. So we’ll end wrote a simple class to ensure keys are unique when passed in. It should always run on re render so we don’t end up caching old instances of keys , since whenever it encounters duplicates it will provision a new unique key for it
z
What's the point of using keys at all then? The whole point of keys is to give each item a stable identifier when the list changes, which it sounds like you're intentionally not doing.
a
Well they do, because they are stable. It’s just when we rerender or paginate we will encounter dupes at times
So if we remove keys entirely are there any consequences for state restoration?
z
This sounds like a problem that should be solved in the repository or presentation layer or something, doesn’t seem like a view layer problem.
☝️ 4
☝🏾 1
a
Scroll position when navigating?
It also should help during recomposing. Essentially the generator stores a map of all keys encountered. If a dupe is found then it provisions same id with an index after it. So they are stable, because recomposing and updating items at the end will produce same key results between recomposing
p
Could you maybe filter out the duplicates on mobile side? Or if it's in a paging list, you could add page index to your keys - e.g.
$pageIndex_$itemId
. I'm doing that (our backend returns duplicates in other pages...) and it usually works great.
105 Views