[iOS] Switch with a role that has no iOS trait stops being a switch to accessibility after it is disabled and re-enabled

Đang mở
#59,334 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@r1shabhsharma05 đang làm issue này rồi.

Từ ngày 22/10/2026.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ios, objective-c, react-native
Lĩnh vực
accessibility, mobile

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Component: Switch Needs: Triage :mag: Platform: iOS Type: New Architecture
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:

  1. On mount the derived traits are None, the same as the default, so nothing is written and the UISwitch keeps UIKit's own traits, including the switch trait.
  2. When disabled, the derived traits are NotEnabled, which replaces UIKit's traits.
  3. When enabled again, the derived traits go back to None. That now differs from the previous value, so 0 is 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
  1. Clone the reproducer, then cd ReproducerApp && npm install && (cd ios && bundle install && bundle exec pod install) and npx react-native run-ios.
  2. Inspect the three switches with Accessibility Inspector: all three are switches.
  3. Press "Disable switches", then "Enable switches".
  4. Inspect them again: the role="none" and role="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).

Ngôn ngữ chính
C++
Star
127k
Fork
25.5k
Merge trung bình
3 ngày 18 giờ
Pull request đã merge (30 ngày)
188

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react/react-native

Tất cả issue của react/react-native

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.