Pagination for the LazyColumnFor

1.1k views Asked by At

Jetpack compose released with alpha version and I want to implement paging for the LazyColumnFor compose function. But I can't understand how we can do this because I can't find something to determine scroll position or something similar. Do we have this opportunity right now or this mechanism will be add in the future?

1

There are 1 answers

0
Ryan M On BEST ANSWER

There is, as of the initial alpha release, not currently a way to detect scroll position. It will be added later, though, with an API something like:

Column {
    val state = rememberLazyListState()
    Text("First item: ${state.firstVisibleItemIndex}")
    LazyColumnFor(
        (0..100).toList(),
        Modifier.fillMaxWidth(),
        state = state
    ) {
        Text("$it", style = currentTextStyle().copy(fontSize = 40.sp))
    }
}

This will (once that is merged) display the first visible scroll position in the list.