Overscroll handling in Jetpack Compose

Viewed 2041

I'm trying to create a Pull-to-Refresh logic in my app.

I know it starts with handling Overscrolling, but I can't seem to find anything in compose that has to do with Overscrolling.

Is it not implemented in Compose yet? Or is it hidden somewhere?

I'm using a LazyColumn right now, I didn't find anything in the LazyListState.

1 Answers

You can use the Swipe Refresh feature included in Google's Accompanist library.

Example usage:

val viewModel: MyViewModel = viewModel()
val isRefreshing by viewModel.isRefreshing.collectAsState()

SwipeRefresh(
    state = rememberSwipeRefreshState(isRefreshing),
    onRefresh = { viewModel.refresh() },
) {
    LazyColumn {
        items(30) { index ->
            // TODO: list items
        }
    }
}

See the docs for more details.

Related