Conversation
m-bert
commented
Apr 23, 2026
|
|
||
| export default class NativeViewGestureHandler extends GestureHandler { | ||
| private buttonRole!: boolean; | ||
| private switchRole!: boolean; |
Collaborator
Author
There was a problem hiding this comment.
Ideally I'd like to keep this as one variable. It doesn't make much sense now, but I'll investigate it later (possibly with our TextInput) and move it to one variable to keep role in one place, not using this "one-hot" tactic.
Contributor
There was a problem hiding this comment.
Pull request overview
Aligns Switch gesture-handler behavior across iOS and web by adapting platform-specific event/hierarchy differences so RNGH can consistently activate and dispatch its state flow for Switch.
Changes:
- Web: Detect
Switchvia aninput[role="switch"]within the wrapper element and treat it like a “button-like” control for immediate activation. - iOS: Special-case
UISwitchby dispatching RNGH state transitions from a control event callback instead of relying onTouchDown.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/src/web/handlers/NativeViewGestureHandler.ts | Adds switch-role detection and adjusts activation/move handling to support the web Switch DOM structure. |
| packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm | Adds UISwitch special handling by routing gesture event flow through a new handleSwitch callback. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This reverts commit be6a711.
j-piasecki
approved these changes
Apr 23, 2026
m-bert
added a commit
that referenced
this pull request
Apr 27, 2026
## Description In #4112 I've adjusted `Native` gesture for `Switch` component on web. Using `querySelector` on `view` broke our example app, as now it looks for `input` element in the whole subtree. To fix this, I've added [`:scope >`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:scope#using_scope_in_javascript) which limits `querySelector` only to direct children. ## Test plan `expo-example` on web
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
This PR aims to align
Switchbehavior across platforms.iOS
On
iOSonly first tap on switch would work, later calls would be suppressed. Turns out thatUISwitchtriggers onlyUIControlEventTouchUpInsideandUIControlEventValueChangedcallbacks - noUIControlEventTouchDown. This was verified on standalone, native iOS app inSwiftUI.To fix that, I've moved Gesture Handler events flow to
UIControlEventValueChanged.web
On web there's a problem with hierarchy - current implementation assumes that our
viewisSwitch. In reality it isdivwrapper that containsinputand other stuff that build this component.Test plan
Tested on the following example