With the `LazyListState` how do I write a function...
# compose
o
With the
LazyListState
how do I write a function to “bring item into view”? So that it would do minimal required scrolling to make an item entirely visible. I can’t find all the needed data, or just slow tonight 🙂
m
Have you tried the "animateScrollToItem" function on LazyListState?
c
Oh yeah, that’s better ^^
o
animateScrollToItem
scrolls the list so that requested index is first one. E.g. if I want to bring into view an item just next to the last visible index, it would scroll too much
c
I've only used BringIntoViewRequester with text fields, so I'm not sure if the overall effect on, say, a Box
a
You can copy the source of
animateScrollToItem
and make some changes.
j
You could take a look at
andrdoix.compose.wear.material.ScalingLazyColumn
for inspiration as we scroll items to the center of the screen rather than the top
o
My use case is pretty simple, actually. I have a LazyColumn, and I’m adding keyboard navigation there (it’s on desktop). So when user gets to the last item and hits down, I need to scroll it just a bit to make item fully visible.
z
BringIntoViewRequester doesn’t currently work great with lazy lists because we need to provide the list with additional signal so it doesn’t immediately dispose the newly-focused item. Please follow https://issuetracker.google.com/issues/179203700
o
I don’t use focus there, because I have a quick search text input that keeps the focus. I’m intercepting up/down keys and changing “active” item manually.