I need to have a composable and an android view co...
# compose
d
I need to have a composable and an android view collaboratively detect pointer events in a view. I want the composable to get access to the events first, and decide if it wants to exclusively handle them or if it wants the view to see them as well. Because I need to switch which composable renders above the android view without recreating the android view, (I think) I need them to be siblings.
Copy code
Box(Modifier.fillMaxSize()) {
        AndroidView(/* ... */)
        
        when (foo) {
           is Bar -> Box(Modifier.fillMaxSize().pointerInput(key) { /* ... */ }
           is Buzz -> Box(Modifier.fillMaxSize().pointerInput(key) { /* ... */ }
           / * ... */
        }
}
The problem is both
Modifier.pointerInteropFilter
(even returning false) and
Modifier.pointerInput
(even with an empty block) prevent the view from seeing any pointer events.
f
I think this isn't the best solution, but you can have an state and your composables can update it if needed when a pointer event occurs. Then when that state changes you trigger something in your AndroidView. (it is not very performant i guess, but it must work)
👍 1