[Web] Assign role for Native gesture in detector#4130
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a web-specific mechanism to tag “Native” gesture targets with a semantic role so NativeViewGestureHandler can apply role-dependent behavior when used via v3 Native/Virtual detectors.
Changes:
- Introduces
NativeGestureRoleplus arngh-roleDOM attribute constant for role tagging on web. - Updates
HostGestureDetector.webandVirtualDetectorto set the role attribute based on the wrapped child’sdisplayName. - Refactors
NativeViewGestureHandlerto use a singlerolefield (instead ofbuttonRole/switchRole) and to read the role from the new attribute for detector-based paths.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/web/interfaces.ts | Adds NativeGestureRole enum. |
| packages/react-native-gesture-handler/src/web/constants.ts | Adds NATIVE_GESTURE_ROLE_ATTRIBUTE (rngh-role). |
| packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts | Makes actionType protected for subclass access. |
| packages/react-native-gesture-handler/src/web/handlers/NativeViewGestureHandler.ts | Reads role from rngh-role for detector paths; consolidates role handling. |
| packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx | Sets rngh-role on the native-detector child element based on displayName. |
| packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/VirtualDetector.tsx | Attempts to set rngh-role for virtual-detector children on web. |
| packages/react-native-gesture-handler/src/components/GestureHandlerButton.web.tsx | Sets ButtonComponent.displayName = 'Button' to enable role inference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ); | ||
| }; | ||
|
|
||
| ButtonComponent.displayName = 'Button'; |
There was a problem hiding this comment.
Do we want to change that to GestureHandlerButton or do we want to keep it generic?
I'm not sure whether this will behave well with other components, given the integration between native gesture and button.
| [props.children] | ||
| ); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Can this be a custom hook in its own file, which will no-op on native and contain the logic for web (.ts and .web.ts)?
| useRequiredInterceptingDetectorContext(); | ||
|
|
||
| const viewRef = useRef(null); | ||
| const viewRef = useRef<HTMLElement | null>(null); |
There was a problem hiding this comment.
This can be part of the new hook as well
| }); | ||
| }; | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Any chance to unify this with the one in virtual detector?
Description
In this PR I change how the role is assigned to
Nativegesture. Previously we relied on different checks, likehasAttributeandquerySelector. In this PR I changed it so that Detector usesdisplayNameto determine underlying component.I've also removed double
hitSlopassignment (289c922)Test plan
Tested on the following example: