Compose中的androidView在NestedScrollView中丢失触摸事件 [英] AndroidView in Compose loses touch events in NestedScrollView

查看:14
本文介绍了Compose中的androidView在NestedScrollView中丢失触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个普通的XML视图,在NestedScrollView中有一个LinearLayout。里面有一个普通视图和一个包含androidView的可合成视图。

布局:

<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
        }
    })
}

在撰写文章中点击查看时,滚动不起作用。点击监听程序接收所有触摸事件。

有什么方法可以让Android View在Compose内部点击时行为正常吗?

推荐答案

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

这篇关于Compose中的androidView在NestedScrollView中丢失触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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