Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -56,6 +56,7 @@ class GestureHandlerOrchestrator(
private set
private var handlingChangeSemaphore = 0
private var finishedHandlersCleanupScheduled = false
private var interceptedViewsCancelScheduled = false
private var activationIndex = 0

/**
Expand All @@ -74,6 +75,11 @@ class GestureHandlerOrchestrator(
cancelAll()
}
deliverEventToGestureHandlers(event)
if (interceptedViewsCancelScheduled) {
interceptedViewsCancelScheduled = false
cancelTouchesInInterceptedViews(event)
}
releasePointerDownPoints(event)
isHandlingTouch = false
if (finishedHandlersCleanupScheduled && handlingChangeSemaphore == 0) {
cleanupFinishedHandlers()
Expand Down Expand Up @@ -759,18 +765,26 @@ class GestureHandlerOrchestrator(
}

private fun trackPointerDownPoints(event: MotionEvent) {
val index = event.actionIndex
val action = event.actionMasked
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) {
val index = event.actionIndex
pointerDownPoints.put(event.getPointerId(index), PointF(event.getX(index), event.getY(index)))
}
}

// Runs after the event is handled, so a sweep started by a lifting pointer still sees it.
private fun releasePointerDownPoints(event: MotionEvent) {
when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN ->
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()
MotionEvent.ACTION_POINTER_UP -> pointerDownPoints.remove(event.getPointerId(event.actionIndex))
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> pointerDownPoints.clear()
}
}

fun cancelTouchesInInterceptedViews(event: MotionEvent) {
fun scheduleInterceptedViewsCancel() {
interceptedViewsCancelScheduled = true
}

private fun cancelTouchesInInterceptedViews(event: MotionEvent) {
viewsToCancel.clear()
for (i in 0 until pointerDownPoints.size()) {
val point = pointerDownPoints.valueAt(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
private val jsGestureHandler: GestureHandler?
val rootView: ViewGroup
private var shouldIntercept = false
private var wasIntercepting = false
private var passingTouch = false
private var passingNativeTouch = false
private var nativeTouchGrabRequested = false
Expand Down Expand Up @@ -115,6 +114,11 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
override fun onHandleHover(event: MotionEvent, sourceEvent: MotionEvent) = handleEvent(event)

override fun onCancel() {
// 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`.
if (!shouldIntercept) {
orchestrator?.scheduleInterceptedViewsCancel()
}
shouldIntercept = true
}
}
Expand Down Expand Up @@ -185,13 +189,6 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
orchestrator!!.onTouchEvent(event)
passingTouch = false

// 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`
if (shouldIntercept && !wasIntercepting) {
orchestrator!!.cancelTouchesInInterceptedViews(event)
}
wasIntercepting = shouldIntercept

return shouldIntercept
}

Expand Down
Loading