Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class GestureHandlerOrchestrator(
private val viewConfigHelper: ViewConfigurationHelper,
private val rootView: ViewGroup,
private val onJSResponderCancelListener: OnJSResponderCancelListener,
private val onTouchEventProcessed: (MotionEvent) -> Unit = {},
) {
/**
* Minimum alpha (value from 0 to 1) that should be set to a view so that it can be treated as a
Expand Down Expand Up @@ -74,6 +75,12 @@ class GestureHandlerOrchestrator(
cancelAll()
}
deliverEventToGestureHandlers(event)
// A discrete handler can start interception on UP. Cancel native touches before losing
// their DOWN positions or resetting the native handlers that still own their views.
onTouchEventProcessed(event)
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
pointerDownPoints.clear()
}
isHandlingTouch = false
if (finishedHandlersCleanupScheduled && handlingChangeSemaphore == 0) {
cleanupFinishedHandlers()
Expand Down Expand Up @@ -765,8 +772,6 @@ class GestureHandlerOrchestrator(
pointerDownPoints.put(event.getPointerId(index), PointF(event.getX(index), event.getY(index)))
MotionEvent.ACTION_POINTER_UP ->
pointerDownPoints.remove(event.getPointerId(index))
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL ->
pointerDownPoints.clear()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
RNViewConfigurationHelper(),
rootView,
onJSResponderCancelListener,
::onTouchEventProcessed,
).apply {
minimumAlphaForTraversal = MIN_ALPHA_FOR_TOUCH
}
Expand Down Expand Up @@ -185,14 +186,17 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
orchestrator!!.onTouchEvent(event)
passingTouch = false

return shouldIntercept
}

private fun onTouchEventProcessed(event: MotionEvent) {
// On the transition into interception, cancel the native views the pointers landed on - the
// framework's ACTION_CANCEL never reaches them since RNGH ignores `onInterceptTouchEvent`
// framework's ACTION_CANCEL never reaches them since RNGH ignores `onInterceptTouchEvent`.
// Keep this inside the orchestrator's dispatch so its own CANCEL is not a native touch grab.
if (shouldIntercept && !wasIntercepting) {
orchestrator!!.cancelTouchesInInterceptedViews(event)
}
wasIntercepting = shouldIntercept

return shouldIntercept
}

fun activateNativeHandlers(view: View) {
Expand Down