首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >滚动LazyColumn在BottomSheetDialogFragment中的问题

滚动LazyColumn在BottomSheetDialogFragment中的问题
EN

Stack Overflow用户
提问于 2022-01-20 18:29:20
回答 3查看 2K关注 0票数 1

我在BottomSheetDialogFragment中使用BottomSheetDialogFragment,但是如果要向上滚动LazyColumn列表,则Bottom工作表对话框滚动而不是LazyColumn列表。似乎BottomSheetDialogFragment拦截用户的触摸输入。

这就是它的样子:

如何在LazyColumn中正确使用BottomSheetDialogFragment

MyBottomSheetDialogFragment.kt:

代码语言:javascript
运行
复制
class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireContext()).apply {
            setContent {
                Column(horizontalAlignment = Alignment.CenterHorizontally) {
                    Text("Header", color = Color.Black)
                    LazyColumn(
                        Modifier
                            .weight(1f)
                            .fillMaxWidth()) {
                        items(100) {
                            Text("Item $it", Modifier.fillMaxWidth(), Color.Black)
                        }
                    }
                }
            }
        }
    }
}

并使用以下代码显示:

代码语言:javascript
运行
复制
MyBottomSheetDialogFragment().show(activity.supportFragmentManager, null)

当我们使用XML时,为了解决这个问题,我们必须用类似于RecyclerViewNestedScrollView包装RecyclerView列表,但是如何用Jetpack修复它呢?

EN

回答 3

Stack Overflow用户

发布于 2022-05-13 09:47:08

因为组合1.2.0-beta01问题可以用rememberNestedScrollInteropConnection来解决

代码语言:javascript
运行
复制
Modifier.nestedScroll(rememberNestedScrollInteropConnection())

在我的例子中,BottomSheetDialogFragment是标准的View,它有带有id containerComposeView。在onViewCreated中,我需要:

代码语言:javascript
运行
复制
binding.container.setContent {
    AppTheme {
        Surface(
            modifier = Modifier.nestedScroll(rememberNestedScrollInteropConnection())
        ) {
            LazyColumn {
                // ITEMS
            }
        }
    }
}

现在列表正在以正确的方式滚动。

票数 6
EN

Stack Overflow用户

发布于 2022-01-24 15:05:57

您可以尝试一下这个https://gist.github.com/chrisbanes/053189c31302269656c1979edf418310

这是https://issuetracker.google.com/issues/174348612的一个解决方案,这意味着Compose中的嵌套滚动布局在视图系统中不作为嵌套滚动子结构工作。

在您的案例中,示例用法:

代码语言:javascript
运行
复制
class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireContext()).apply {
            setContent {
                Surface(
                    modifier = Modifier.nestedScroll(rememberViewInteropNestedScrollConnection())
                ){
                    LazyColumn(
                        Modifier
                            .weight(1f)
                            .fillMaxWidth()) {
                        items(100) {
                            Text("Item $it", Modifier.fillMaxWidth(), Color.Black)
                        }
                    }
                }
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70791568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档