[Android] Set AccessibilityNodeInfo.stateDescription so TalkBack stops reading "checked. on." on switches
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
On Android, a view with accessibilityRole="switch" and accessibilityState={{ checked: true }} is read by TalkBack as "checked. on.". TalkBack takes "on" from the Switch class name and "checked" from isChecked. It suppresses the generic word only when stateDescription is set (API 30+).
ReactAccessibilityDelegate.kt on main never calls setStateDescription: for STATE_CHECKED it sets only isCheckable and isChecked. No JS prop reaches stateDescription, so apps can't fix this without native code.
A related request, #34736 ("Custom State Descriptions"), was closed by the stale bot in 2023 without a PR.
Steps to reproduce
- Render
<Pressable accessibilityRole="switch" accessibilityState={{ checked: true }} accessibilityLabel="Notifications" />. - Turn on TalkBack and focus the element.
- Hear "checked. on." in the announcement.
Expected
The state is read once ("on"), not twice.
Suggested fix
In ReactAccessibilityDelegate, when accessibilityState.checked is set, also call ViewCompat.setStateDescription (or AccessibilityNodeInfoCompat.setStateDescription). For role switch it would be "on"/"off", and for role checkbox "checked"/"not checked", using Android's own localized strings. Alternatively, expose accessibilityValue.text as the stateDescription.
Versions
- React Native 0.85.3 (Expo SDK 56). Also confirmed on
mainup to v0.88.0-rc.1 by reading the source. - TalkBack 17.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 ReactAccessibilityDelegate.kt 中 STATE_CHECKED 的处理开始,跟踪 accessibilityRole 和 accessibilityState 如何传递到 Android 节点。比较针对 switch 和 checkbox 角色的 ViewCompat 或 AccessibilityNodeInfoCompat stateDescription 建议行为,然后验证公告不再重复状态,同时现有的无障碍行为保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, kotlin, react-native
- 领域
- accessibility, mobile
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100