I'm implementing a custom "long press drag" compos...
# compose
t
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
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
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
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
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.
374 Views