Jetpack Compose 中的过度滚动处理 [英] Overscroll handling in Jetpack Compose

查看:95
本文介绍了Jetpack Compose 中的过度滚动处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中创建下拉刷新逻辑.

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

我知道它从处理 Overscrolling 开始,但我似乎无法在 compose 中找到任何与 Overscrolling 有关的东西.

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

它还没有在 Compose 中实现吗?还是藏在某个地方?

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

我现在正在使用 LazyColumn,我在 LazyListState 中没有找到任何内容.

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

推荐答案

您可以使用 Google 的 伴奏图书馆.

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

示例用法:

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.

这篇关于Jetpack Compose 中的过度滚动处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆