I’m using M3 `ModalNavigationDrawer` with `gesture...
# compose
m
I’m using M3
ModalNavigationDrawer
with
gesturesEnabled = true
. I noticed that when the
Scaffold
content is something like
HorziontalPager
the open drawer gesture doesn’t work, with the pager seeming taking priority. This is good. However, when the scaffold content contains my custom composable where the user can draw strokes (I use
Modifier.pointerInteropFilter
for this), then the drawer gestures take priority and so no strokes can be drawn. My current workaround is to explicitly disable drawer gestures when that composable is visible. But is there a better way perhaps involving priority with which pointer events are consumed?
a
There is a
requestDisallowInterceptTouchEvent
parameter. You should invoke the lambda if you don’t want pointer input to be stolen by parent, same as in the view world.
m
Thank Albert. So I see I can pass an instance of
RequestDisallowInterceptTouchEvent()
to
pointerInteropFilter
and the documentation says “you can later call it” but when should it be called?
a
When you detected that a gesture has started and you want to handle the following events of the gesture.
m
Do you mean at the
ACTION_DOWN
here? Seems weird though seems to work!
Copy code
val requestDisallowInterceptTouchEvent = remember { RequestDisallowInterceptTouchEvent() }
modifier = Modifier
    .pointerInteropFilter(
        requestDisallowInterceptTouchEvent = requestDisallowInterceptTouchEvent,
    ) { event ->
        val offset = Offset(event.x, event.y)
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                requestDisallowInterceptTouchEvent(true)
                onStartStroke(offset)
            }
            MotionEvent.ACTION_MOVE -> onPushPoint(offset)
            MotionEvent.ACTION_UP -> onFinishStroke(offset)
        }
        true
    }
a
Yeah that's how it works.
thank you color 1
m
Seems I don’t need to
requestDisallowInterceptTouchEvent(false)
in
ACTION_UP
a
Yes, it will be reset for each gesture.
👍 1