[iOS] Switch with a role that has no iOS trait stops being a switch to accessibility after it is disabled and re-enabled
維護者通常 2 天內回覆
@r1shabhsharma05 已經在處理了。
開始於 2026年10月22日。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- ios, objective-c, react-native
- 領域
- accessibility, mobile
研究方向
Start by reading the accessibility trait update path in RCTViewComponentView and how RCTSwitchComponentView exposes its inner UISwitch as the accessibility element. Compare the traits on mount with those written after disabling and re-enabling a switch whose role maps to no iOS trait. Done when the role reported to accessibility remains consistent through that cycle; the issue provides a reproducer and observed accessibility tree to check.
由索引模型根據 Issue 內容生成。
描述
Description
On iOS, a Switch whose role maps to no iOS accessibility trait, such as accessibilityRole="none" or accessibilityRole="checkbox", is reported to accessibility as a switch on mount. Once its accessibilityState.disabled goes from true back to false, it is reported as a generic element instead, and stays that way. A Switch with the default role stays a switch throughout.
The inner UISwitch is the Switch's accessibility element (RCTSwitchComponentView), and RCTViewComponentView writes the traits derived from the role and accessibilityState onto it only when they change:
- On mount the derived traits are
None, the same as the default, so nothing is written and theUISwitchkeeps UIKit's own traits, including the switch trait. - When disabled, the derived traits are
NotEnabled, which replaces UIKit's traits. - When enabled again, the derived traits go back to
None. That now differs from the previous value, so0is written explicitly and UIKit's switch trait does not come back.
Expected: the Switch is reported with the same role before and after a disable and enable cycle. Whether that role should be UIKit's switch or the one the role asks for, it should not depend on whether the Switch has been disabled before.
Related: #59333 makes disabled set accessibilityState.disabled on iOS, as Android already does. With that change, toggling disabled alone also triggers this.
Steps to reproduce
- Clone the reproducer, then
cd ReproducerApp && npm install && (cd ios && bundle install && bundle exec pod install)andnpx react-native run-ios. - Inspect the three switches with Accessibility Inspector: all three are switches.
- Press "Disable switches", then "Enable switches".
- Inspect them again: the
role="none"androle="checkbox"switches are now generic elements. The default-role switch is still a switch.
The app renders:
<Switch value disabled={disabled} accessibilityState={{disabled}} />
<Switch value disabled={disabled} accessibilityRole="none" accessibilityState={{disabled}} />
<Switch value disabled={disabled} accessibilityRole="checkbox" accessibilityState={{disabled}} />
React Native Version
0.88.0
Affected Platforms
Runtime - iOS, Build - MacOS
Areas
Fabric - The New Renderer
Output of npx @react-native-community/cli info
System:
OS: macOS 26.6.2
CPU: (8) arm64 Apple M5 Pro (Virtual)
Memory: 135.64 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 24.20.0
path: ~/.fnm/bin/node
Yarn:
version: 1.22.22
path: ~/.fnm/bin/yarn
npm:
version: 11.19.0
path: ~/.fnm/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.17.0
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 27.0
- iOS 27.0
- macOS 27.0
- tvOS 27.0
- visionOS 27.0
- watchOS 27.0
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode:
version: 27.0/27A5228h
path: /usr/bin/xcodebuild
Languages:
Java: Not Found
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: 20.2.0
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.88.0
wanted: 0.88.0
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
No crash. Accessibility tree read with `axe describe-ui` (https://github.com/cameroncooke/AXe) on an iPhone 17 Pro simulator, iOS 27:
1. On mount
role-default CheckBox role_description='switch' enabled=True
role-none CheckBox role_description='switch' enabled=True
role-checkbox CheckBox role_description='switch' enabled=True
2. After "Disable switches"
role-default CheckBox role_description='switch' enabled=False
role-none GenericElement role_description='' enabled=False
role-checkbox GenericElement role_description='' enabled=False
3. After "Enable switches"
role-default CheckBox role_description='switch' enabled=True
role-none GenericElement role_description='' enabled=True
role-checkbox GenericElement role_description='' enabled=True
MANDATORY Reproducer
https://github.com/arun279/rn-switch-role-a11y-reproducer
Screenshots and Videos
Nothing visual: the switches look the same before and after. The difference is only in the accessibility tree (see the logs above).
- 主要語言
- C++
- 星號
- 127k
- 分支
- 25.5k
- 平均合併
- 3 天 18 小時
- 30 天內合併 PR
- 188
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
react/react-native 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
react/react-native#59945 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
react/react-native#59944 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
react/react-native#59942 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
react/react-native#59939 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
react/react-native#59929 · 1 則留言 ·
維護者通常 2 天內回覆
查看 react/react-native 的全部 Issue
相似的 Issue
-
backlog
難度 2/5 1-3 小時 新手友好度 78/100
EchoTools/nevr-runtime#2385 ·
維護者通常 1 天內回覆
-
type:bug
難度 2/5 1-3 小時 新手友好度 65/100
tensorflow/tflite-micro#3995 ·
維護者通常 1 天內回覆
-
CPU update 1.31x未關閉speed-report
難度 1/5 1 小時以內 新手友好度 75/100
mw00/project-maya#961 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
not for AI lovers
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆