[Web] Correctly attach v3 handlers#4194
Open
m-bert wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
GestureHandlerWebDelegateto choose the attachment view differently for native/virtual detector action types. - Move the “native/virtual detector” check onto the web
GestureHandlerclass and use it at call sites. - Extend the web
IGestureHandlerinterface withusesNativeOrVirtualDetector()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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onPressablewere incorrectly attached to thebutton,StateMachinestopped working, since it expectedNativegesture event, but gotLongPressevent instead see here.This PR moves
usesNativeOrVirtualDetectordirectly toGestureHandler(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
viewRefis passed fromHostGestureDetector, so it is correctly set to either detector view withdisplay: contents;orfirstChild, ifNativegesture is used.Test plan
Tested on example app (Nested Pressables and some other examples)