Skip to content

[Web] Correctly attach v3 handlers#4194

Open
m-bert wants to merge 2 commits into
mainfrom
@mbert/correctly-attach-handlers
Open

[Web] Correctly attach v3 handlers#4194
m-bert wants to merge 2 commits into
mainfrom
@mbert/correctly-attach-handlers

Conversation

@m-bert
Copy link
Copy Markdown
Collaborator

@m-bert m-bert commented May 25, 2026

Description

V3 gestures on web were attached incorrectly to the child view, not the detector itself. This could be observed in Pressable - #4179 changed order of attaching gestures. Because all gestures on Pressable were incorrectly attached to the button, StateMachine stopped working, since it expected Native gesture event, but got LongPress event instead see here.

This PR moves usesNativeOrVirtualDetector directly to GestureHandler (there's no need to keep it as separate function) and then uses this check in web delegate to correctly handle v3 view assignment.

Note

This works because in v3 viewRef is passed from HostGestureDetector, so it is correctly set to either detector view with display: contents; or firstChild, if Native gesture is used.

Test plan

Tested on example app (Nested Pressables and some other examples)

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

Fixes web v3 gesture attachment so handlers bind to the detector element (instead of being implicitly resolved to its child), addressing issues like Pressable state machine receiving the wrong event source after the attachment ordering change in #4179.

Changes:

  • Update GestureHandlerWebDelegate to choose the attachment view differently for native/virtual detector action types.
  • Move the “native/virtual detector” check onto the web GestureHandler class and use it at call sites.
  • Extend the web IGestureHandler interface with usesNativeOrVirtualDetector() so delegates/handlers can branch consistently.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/react-native-gesture-handler/src/web/tools/GestureHandlerWebDelegate.ts Uses handler.usesNativeOrVirtualDetector() to decide whether to use the detector element directly vs resolving via findNodeHandle.
packages/react-native-gesture-handler/src/web/handlers/NativeViewGestureHandler.ts Switches to the new this.usesNativeOrVirtualDetector() method.
packages/react-native-gesture-handler/src/web/handlers/IGestureHandler.ts Adds usesNativeOrVirtualDetector() to the web handler contract.
packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts Introduces usesNativeOrVirtualDetector() and replaces the previous helper usage at call sites.

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

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

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

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.

2 participants