Hello! How do I handle click event without consumi...
# compose-desktop
l
Hello! How do I handle click event without consuming them? Say that you have a
Box
with a such modifier to intercept the clicks and do stuff, but I want the
content
of the box to also receive the clicks!
@Igor Demin :3
i
There is no a high-level modifier for that (clickable or onClick). But you can add
Modifier.pointerInput
to the Box and react to events, without consuming them (
event.consume()
is called by clickable or onClick, for example)
p
I had a similar one, here: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1677561456829879 The closest I got was Modifier.nestedScroll(connection, dispatcher) but still, the parent event dispatching worked when the Parent composable is a Pager but not when it is a NavigationDrawer. Perhaps we need a modifier similar Android Modifier.pointerInteropFilter, it gives you the chance to get the event stream and participate/not-participate in the consumption by returning true/false in the dispatching function/lambda.
Using Modifier.pointerInput and not consuming the event, did not work for me. Perhaps a bug 🪲🤔
z
I think you’d need to use the Initial input pass to do this, not the default Main. Initial is top-down, Main is bottom-up.
p
Initial
and
Main
first time I heard of it. Could you point out some documentation in regards Zach. I am consuming Main apparently, because I noticed my events gets passed to the inner most composable.
p
Thanks Zach, I was able to achieve what I want it. Using a combination of
Copy code
forEachGesture {
    awaitPointerEventScope {
         val eventDown = awaitFirstDown(requireUnconsumed = true)
         ... 
          do {

              val event: PointerEvent = awaitPointerEvent(PointerEventPass.Main)
              ...                      
                                   
          } while (event.changes.any { it.pressed })
ephemient had given me some directions in another thread. I understand the touch API better now. Bellow is a video of what I was describing.