How do I implement auto scrolling to an item in La...
# compose-desktop
m
How do I implement auto scrolling to an item in LazyColumn? I.e. when I press up or down key a sibling item is selected and I want to scroll to it if it's outside of the viewport. It may also be some random item in the list. When the item is `focusable`then the LazyColumn tries to nicely do what I want but succeeds only sometimes and only when the item is within it's cache I suppose, i.e. directly below the bottom. It works well with regular Column though. There is also `scrollToItem`but 1. it only snaps the given item to top 2. is terribly laggy. (If it didn't take seconds to populate Column with 200 items I'd be fine with it too.)
k
See https://github.com/kirill-grouchnikov/aurora/blob/icicle/demo/src/desktopMain/kotlin/org/pushingpixels/aurora/demo/AuroraScrollDemo.kt#L57 for detecting if an item is visible. Then you can use something like this:
Copy code
scope.launch {
  if (!lazyListState.isItemFullyVisible(index)) {
        lazyListState.animateScrollToItem(index)
  }
}
👀 1
m
Still scrolls whole page when going down. But since there is `layoutInfo`maybe it can help overcome that? I assume the best way would be to dig into the source and fix what the LazyColumn tries to do with focus, I have not found that place though.