简体   繁体   中英

AndroidView in Compose loses touch events

I have a normal XML view with a LinearLayout inside a ScrollView. Inside there is a normal View and a Composable view which contains an AndroidView.

The layout:

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

The ComposeView is set like this:

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

When tapping the View inside a Compose the scroll doesn't work. The click listener eats all touch events.

Is there any way to make Android View click inside Compose behave correctly?

Usually there is a Boolean exposed called as requireUnconsumed in all such cases. I'm not really sure about the particular implementation since it concerns interop, not something that I might wanna get into, I'd say just read the docs. Seriously, you'll find it there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM