Okay so I've got a really interesting questions here. Let's talk snapping. Now that snapping is a 1st class api (RIP Snapper lib) available for compose devs using LazyColumn, a fundamental question has arose... how do I initialize the LazyColumn so that it comes on screen beautifully and perfectly snapped to a defined index/item element in the column rather than visually resting halfway between two elements ? Why no snap? https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapFlingBehavior As you can see here, its very easy and useful to add the snap fling behavior to your LazyColumns - especially if you have long lists in your app. It makes it so anytime you scroll or fling the column, it will snap perfectly onto the final item nearest the center of the LazyColumn Widger The problem is, there is no snapToIndex method provided.... and animateToScrollIndex does not seem Snap friendly as it results in the triggered scroll animation resting to a final location between two elements. Nothing I have tried leads to snapping to an item index programatically. Any ideas ?? There has got to be some possible way to solve this fundamental issue. If there's a way to do this, it could greatly increase the utility of SnapFlingBehavior in LazyColumn and LazyRow world (imho some of the most vital performance related widgets in the framework).
Has anyone found a solution to programmatically controlling the index you are currently snapped to ?
/** Basic usage **/
val listState = rememberLazyListState()
val flingBehavior = rememberSnapFlingBehavior()
LazyColumn(state = listState, flingBehavior = flingBehavior)
/** Exampe of things that don't result in snapping to an index **/
listState by rememberLazyListState(firstVisibleItemIndex: 5)
listState.animateScrollTo(index: 10)