You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f0c98c7
Browse filesBrowse the repository at this point in the historyBrowse files
[Android] Properly handle requestDisallowInterceptTouchEvent for v3 (#4367)
## Description
On Android, when a native view calls
`requestDisallowInterceptTouchEvent` (e.g. a pager starting a swipe),
`RNGestureHandlerRootView` reacted by cancelling **all** handlers
registered on the root. `react-native-pager-view` calls it eagerly on
touch down, so any v3 gesture rendered inside a pager (e.g. inside
material top tabs) was cancelled before it could activate — a long press
nested in top tabs never activated at all.
This PR makes the cancellation targeted:
- The root view now cancels only legacy handlers (v1/v2 action types)
via the new `GestureHandlerOrchestrator.cancelAllLegacyHandlers`,
instead of the old trick of activating the internal
`RootViewGestureHandler`. The root handler is now attached with
`ACTION_TYPE_NONE` so it's excluded from that sweep (and no longer sends
dead events to JS).
- v3 handlers are cancelled by new `requestDisallowInterceptTouchEvent`
overrides on `RNGestureHandlerDetectorView` and `ButtonViewGroup`. Since
the request only bubbles upward from the requesting view, only handlers
attached to its ancestors are cancelled — handlers below the requester
(like the long press under the pager) keep working.
- Cancellation is skipped while the orchestrator is delivering events
(`isHandlingTouch`), mirroring the existing `passingTouch` guard, so
disallow requests caused by RNGH's own event delivery don't cancel
gestures.
- `findGestureHandlerRootView` now returns the nearest *enabled* root
view so the checks above consult the orchestrator that actually manages
the subtree.
## Test plan
Tested on reproducer from
#2383https://github.com/user-attachments/assets/4d01dff7-5268-42ff-befa-5c971d39bb4a
---------
Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
Copy file name to clipboardExpand all lines: packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
+26-1Lines changed: 26 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,8 @@ class GestureHandlerOrchestrator(
52
52
// `contains` method on HashSet has O(1) complexity, so calling it inside for loop won't result in O(n^2) (contrary to ArrayList)
Copy file name to clipboardExpand all lines: packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -783,6 +783,24 @@ class RNGestureHandlerButtonViewManager :
Copy file name to clipboardExpand all lines: packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,22 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
Copy file name to clipboardExpand all lines: packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt
Copy file name to clipboardExpand all lines: packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt
0 commit comments