Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overscroll handling in Jetpack Compose

Tags:

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.

like image 279
Ahmad Sattout Avatar asked Jan 07 '21 11:01

Ahmad Sattout


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.

like image 50
Duncan Luk Avatar answered Sep 30 '22 19:09

Duncan Luk