Skip to content

Inline native Switch props in JSX - #59481

Open
javache wants to merge 2 commits into
react:mainfrom
javache:export-D127565462
Open

javache wants to merge 2 commits into
react:mainfrom
javache:export-D127565462

Conversation

@javache

@javache javache commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary:
Remove the intermediate platform prop objects so native Switch prop overrides are explicit in the JSX on both platforms. Behaviour is unchanged.

Changelog: [Internal]

Differential Revision: D127565462

arun279 and others added 2 commits October 26, 2026 04:54
Summary:
On iOS, `<Switch disabled />` is drawn greyed out and ignores taps, but VoiceOver and XCUITest still report it as enabled: the `UIAccessibilityTraitNotEnabled` trait is missing.

Since react#50796, the inner `UISwitch` is the Switch's accessibility element, so `RCTViewComponentView` writes the traits it derives from the role onto the `UISwitch`, replacing the ones UIKit sets, including `NotEnabled`. Since react#57516, `accessibilityState.disabled` adds `NotEnabled` to those traits, but the iOS branch of `Switch.js` never sets it from `disabled`. The Android branch already does.

This moves the existing Android logic above the platform check so iOS gets the same `accessibilityState`. As on Android, `disabled` wins over `accessibilityState.disabled` when both are set. It is done in `Switch.js` rather than `RCTSwitchComponentView` because the Android branch already does it here, and a Switch-specific native writer for the traits would bring back the second trait writer that react#57516 removed.

`disabled` now behaves exactly like `accessibilityState={{disabled: true}}` already does. That includes a Switch whose role maps to no trait, such as `accessibilityRole="none"`: it gets `NotEnabled` alone, without the switch trait.

## Changelog:

[IOS] [FIXED] - Report a disabled `Switch` as disabled to VoiceOver and XCUITest

Pull Request resolved: react#59333

Test Plan:
Added two cases to `Switch-itest.js`: `disabled` overriding `accessibilityState.disabled`, and no `accessibilityState` when `disabled` is not set. Fantom renders the Android branch, so these cover the logic both platforms now share; the iOS side is covered by the manual check below. Each new case fails when its part of the logic is changed.

```
yarn fantom packages/react-native/Libraries/Components/Switch/__tests__/Switch-itest.js
# 6 passed
yarn flow-check
# Found 0 errors
yarn eslint --max-warnings 0 packages/react-native/Libraries/Components/Switch/Switch.js packages/react-native/Libraries/Components/Switch/__tests__/Switch-itest.js
# no warnings
yarn prettier --check packages/react-native/Libraries/Components/Switch/Switch.js packages/react-native/Libraries/Components/Switch/__tests__/Switch-itest.js
# All matched files use Prettier code style!
```

Fantom was built locally on macOS with Xcode 27, whose clang needed `-Wno-deprecated-literal-operator` for the bundled `nlohmann/json.hpp`.

Manual check: a new 0.88.0 app (prebuilt core; `Switch.js` is the same on 0.88.0 and `main`) on an iPhone 17 Pro simulator, iOS 27. For "After", this branch's `Switch.js` was copied into the app's `node_modules/react-native/Libraries/Components/Switch/`. The accessibility tree was read with [AXe](https://github.com/cameroncooke/AXe) `describe-ui`, which reports each element's `enabled` attribute.

```tsx
<Switch testID="disabled-mount" value disabled />
<Switch testID="disabled-live" value disabled={liveDisabled} />
<Switch testID="disabled-state" value disabled accessibilityState={{disabled: true}} />
```

| Switch | Before | After |
| --- | --- | --- |
| `disabled-mount` | enabled | not enabled |
| `disabled-live`, after `disabled` is set to `true` | enabled | not enabled |
| `disabled-live`, after `disabled` is set back to `false` | enabled | enabled |
| `disabled-state` | not enabled | not enabled |

The role (`switch`) and value (`1`) are unchanged.

Not run: VoiceOver on a device.

Reviewed By: rubennorte

Differential Revision: D127141579

Pulled By: javache
Summary:
Remove the intermediate platform prop objects so native Switch prop overrides are explicit in the JSX on both platforms. Behaviour is unchanged.

Changelog: [Internal]

Differential Revision: D127565462
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 26, 2026
@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127565462.

@github-actions

Copy link
Copy Markdown

Visual regression

2 visual difference(s) at 26932cd9572b. Visual differences need maintainer approval. Review the report, then apply visual-change-approved.

ios border/corner-radii/default: Changed, 68005 px (75.561%)

diff

Expected and Captured
Expected Captured
expected captured

ios touchable/highlight/default: Changed, 42 px (0.039%)

diff

Expected and Captured
Expected Captured
expected captured

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants