0

我使用LazyColumninside 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)

当我们使用 XMLRecyclerView列表时,为了解决这个问题,我们必须用这里描述的方法来包装列表RecyclerView但是如何使用 Jetpack Compose 来修复它?NestedScrollView

4

2 回答 2

0

你可以试试这个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-24T15:05:57.470 回答