How would I scroll to an item in a lazy list by ke...
# compose
e
How would I scroll to an item in a lazy list by key? I don’t have the item index unfortunately. My current (bad) idea I’m toying with is copying the entirety of
LazyListState.animateScrollToItem
and making _modifications_™️ but that method will take me a ‘minute’ to understand enough to update.
m
You should already have the items right? If you're calling the item function, you obviously have some way of getting the key. Just lookup the index of that key in your list:
Copy code
val index = itemList.indexOfFirst { it.key == key }
or something like that.
e
Yeah I had to instead implement a way to know the item lazy position before hand. The thing is I have a tree where each node could be “flattened” to the lazy list (each node will add its children recursively) so at first I didnt have the actual lazy item index (needed for
animateScrollToItem
). So I just implemented a way for each node to report its descendant count
327 Views