我在BottomSheetDialogFragment
中使用BottomSheetDialogFragment
,但是如果要向上滚动LazyColumn
列表,则Bottom
工作表对话框滚动而不是LazyColumn
列表。似乎BottomSheetDialogFragment
拦截用户的触摸输入。
这就是它的样子:
如何在LazyColumn
中正确使用BottomSheetDialogFragment
MyBottomSheetDialogFragment.kt:
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)
}
}
}
}
}
}
}
并使用以下代码显示:
MyBottomSheetDialogFragment().show(activity.supportFragmentManager, null)
当我们使用XML时,为了解决这个问题,我们必须用类似于RecyclerView
的NestedScrollView
包装RecyclerView
列表,但是如何用Jetpack修复它呢?
发布于 2022-05-13 09:47:08
因为组合1.2.0-beta01
问题可以用rememberNestedScrollInteropConnection来解决
Modifier.nestedScroll(rememberNestedScrollInteropConnection())
在我的例子中,BottomSheetDialogFragment
是标准的View
,它有带有id container
的ComposeView
。在onViewCreated
中,我需要:
binding.container.setContent {
AppTheme {
Surface(
modifier = Modifier.nestedScroll(rememberNestedScrollInteropConnection())
) {
LazyColumn {
// ITEMS
}
}
}
}
现在列表正在以正确的方式滚动。
发布于 2022-01-24 15:05:57
您可以尝试一下这个https://gist.github.com/chrisbanes/053189c31302269656c1979edf418310。
这是https://issuetracker.google.com/issues/174348612的一个解决方案,这意味着Compose中的嵌套滚动布局在视图系统中不作为嵌套滚动子结构工作。
在您的案例中,示例用法:
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)
}
}
}
}
}
}
}
发布于 2022-01-20 18:35:55
如果您在启动底部工作表对话框片段的活动中使用撰写,那么最好只使用纯组合实现,并利用组合等效的底部工作表组件: ModalBottomSheetLayout。
https://stackoverflow.com/questions/70791568
复制相似问题