Skip to content

Commit 73bc96e

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Announce "unselected" Accessibility State (Android)
Summary: Changes React Native so that when `accessibilityState` is used to change a view from `selected: true` to `selected: false`, the change in state is announced. This is how `checked` works; it is unclear why Android does not do this for `selected`, too. Changelog: [Android][Added] - TalkBack now announces "unselected" when changing `accessibilityState.selected` to false. Reviewed By: blavalla Differential Revision: D27449293 fbshipit-source-id: a6d77b55d63655973ad93c4d5e3743742501f378
1 parent d831134 commit 73bc96e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,17 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
167167
return;
168168
}
169169
if (accessibilityState.hasKey("selected")) {
170-
view.setSelected(accessibilityState.getBoolean("selected"));
170+
boolean prevSelected = view.isSelected();
171+
boolean nextSelected = accessibilityState.getBoolean("selected");
172+
view.setSelected(nextSelected);
173+
174+
// For some reason, Android does not announce "unselected" when state changes.
175+
// This is inconsistent with other platforms, but also with the "checked" state.
176+
// So manually announce this.
177+
if (view.isAccessibilityFocused() && prevSelected && !nextSelected) {
178+
view.announceForAccessibility(
179+
view.getContext().getString(R.string.state_unselected_description));
180+
}
171181
} else {
172182
view.setSelected(false);
173183
}

ReactAndroid/src/main/res/views/uimanager/values/strings_unlocalized.xml

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
name="state_collapsed_description"
9393
translatable="false"
9494
>collapsed</string>
95+
<string
96+
name="state_unselected_description"
97+
translatable="false"
98+
>unselected</string>
9599
<string
96100
name="state_on_description"
97101
translatable="false"

0 commit comments

Comments
 (0)