【问题标题】:AndroidView in Compose loses touch events in NestedScrollViewCompose 中的 AndroidView 在 NestedScrollView 中丢失触摸事件
【发布时间】:2021-11-18 16:08:38
【问题描述】:

我在 NestedScrollView 中有一个带有 LinearLayout 的普通 XML 视图。里面有一个普通的 View 和一个包含 AndroidView 的 Composable 视图。

布局:

<NestedScrollView ...>
    <LinearLayout ...>
       <View .../> <!-- click listener works properly -->
       <androidx.compose.ui.platform.ComposeView .../> <!-- click in inner AndroidView doesn't work properly -->
    </LinearLayout>
</NestedScrollView>

ComposeView 是这样设置的:

composeView.setContent {
    AndroidView(factory = {
        TextView(it).apply {
            setText("View in Compose")
            setOnClickListener { } // This breaks the scroll
        }
    })
}

点击 Compose 中的 View 时,滚动不起作用。点击监听器吃掉所有的触摸事件。

有什么方法可以让 Compose 中的 Android View 点击行为正确吗?

【问题讨论】:

标签: android android-jetpack-compose android-scrollview


【解决方案1】:

在所有此类情况下,通常都会有一个Boolean 暴露,称为requireUnconsumed。我不太确定具体的实现,因为它涉及互操作,而不是我可能想要进入的东西,我想说只是阅读文档。说真的,你会在那里找到它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2021-05-02
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多