Skip to content

[Native] Fix Touchable behavior when nested within gesture handlers#4106

Merged
j-piasecki merged 2 commits intomainfrom
@jpiasecki/fix-nested-gestures-touchables
Apr 23, 2026
Merged

[Native] Fix Touchable behavior when nested within gesture handlers#4106
j-piasecki merged 2 commits intomainfrom
@jpiasecki/fix-nested-gestures-touchables

Conversation

@j-piasecki
Copy link
Copy Markdown
Member

Description

See #4097

Fixes interactions of nested touchables/gestures:

  1. Touchable was missing disallowInterruption: true prop, which caused it to misbehave when used alongside other gestures
  2. Android keeps the list of touch targets internally in each ViewGroup. Since RNGH can start intercepting events mid-stream, this list could contain stale values. The OS, trying to clean it up, would dispatch a synthetic ACTION_CANCEL event, which resulted in the touchable working every other time it's been pressed. To fix that, we do the cleanup by ourselves, by dispatching a synthetic ACTION_CANCEL event before the new event stream starts.

Test plan

Added a new example

This doesn't work correctly on web, but it didn't work before either.

Copilot AI review requested due to automatic review settings April 22, 2026 09:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes nested Touchable interactions when used inside/alongside other gesture handlers, addressing interruption behavior and an Android-specific stale touch-target cleanup issue.

Changes:

  • Add disallowInterruption: true to the v3 Touchable native wrapper configuration.
  • On Android, proactively dispatch a synthetic ACTION_CANCEL to the subtree when a new touch stream starts (ACTION_DOWN) to clear potentially stale touch-target state.
  • Add a new example screen demonstrating nested gestures + touchables and register it in the new API examples list.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/react-native-gesture-handler/src/v3/components/Touchable/Touchable.tsx Sets disallowInterruption: true on the wrapped button to avoid unexpected interruption when nested with other gestures.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt Dispatches a synthetic ACTION_CANCEL at the start of a new stream to pre-clean stale touch-target state on Android.
apps/common-app/src/new_api/tests/nestedTouchables/index.tsx Adds a new manual repro/example for nested touchables + tap gestures and an on-screen event log.
apps/common-app/src/new_api/index.tsx Registers the new “Nested touchables” example in the new API examples list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator

@m-bert m-bert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@j-piasecki j-piasecki merged commit 3dca7f3 into main Apr 23, 2026
12 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/fix-nested-gestures-touchables branch April 23, 2026 12:22
j-piasecki added a commit that referenced this pull request Apr 23, 2026
## Description

1. Adds `stopPropagation` call to event handlers in `Touchable` so only
the inner-most one triggers the active animation.
2. Changes when buttons without `shouldActivateOnStart` (so `Touchable`)
activate - instead of doing it on pressDown, now it happens during
pressUp. This ensures that all other handlers have been extracted and
can be canceled/can cancel `Touchable` correctly.
3. Behavior for buttons with `shouldActivateOnStart` (other buttons)
shouldn't change after this PR, but the proper `shouldActivateOnStart`
implementation is still to be done.

## Test plan

Tested on the example from
#4106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants