https://kotlinlang.org logo
Title
t

Travis Griggs

05/24/2023, 6:06 PM
I'm implementing a custom "long press drag" composable over a GoogleMap composable ( or trying to ). To wit, I've got a structure like the following: Box GoogleMap - fillMaxSize() Canvas - fillMaxSize() - pointerInput(Unit) { detectDragGesturesAfterLongPress( ... ) My drag works great. Unfortunately, it eats not only the long press drag, but all other events as well and nothing makes it through the map when my Canvas is active. I've read through the helpful https://developer.android.com/jetpack/compose/touch-input/pointer-input/understand-gestures, but I'm not finding the solution to this problem in there. My theory is that either a) there's something I could do with my setup to make the gesture detector more cooperative or b) I need to basically inline the gesture detector so that I can manage event consumption more selectively or c) I can't use pointerInput at all and should be using something lower level?
s

Sean Proctor

05/24/2023, 11:29 PM
I'm not super familiar with pointer stuff, but I think it's the detect functions that are consuming your events. The page you linked appears to have the answer. https://developer.android.com/jetpack/compose/touch-input/pointer-input/understand-gestures#handle_events_per_gesture
t

Travis Griggs

05/25/2023, 12:10 AM
So are you saying that (b) is probably the answer? Basically that putting detectXXXXGesture in the AwaitPointerEventScope is not only detect but also an implicit (AndEatOtherEventsWhileWaiting) suffix?
s

Sean Proctor

05/25/2023, 12:18 AM
I think it's a bit of a combination.
detectXXXGesture
is the higher level function. So I guess it's b. I think you could handle the events without consuming them. If you don't want the drag/long press to bleed through, then I think it's much more complicated.
t

Travis Griggs

05/25/2023, 12:29 AM
I'll have to dig a little deeper I guess. Nice that you can see the code of this stuff, instead of the decompiled JDK stuff for other Android things. I can see that the top of the gesture is an awaitEachGesture {}. If I just replace my pointerInput with an empty / logging variant of that, that alone is enough to mask out the GoogleMap below once it gets active. Need to go read up on how that works a little more.