Skip to content

Commit

Permalink
RN: Announce "unselected" Accessibility State (Android)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Apr 6, 2021
1 parent d831134 commit 73bc96e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
return;
}
if (accessibilityState.hasKey("selected")) {
view.setSelected(accessibilityState.getBoolean("selected"));
boolean prevSelected = view.isSelected();
boolean nextSelected = accessibilityState.getBoolean("selected");
view.setSelected(nextSelected);

// For some reason, Android does not announce "unselected" when state changes.
// This is inconsistent with other platforms, but also with the "checked" state.
// So manually announce this.
if (view.isAccessibilityFocused() && prevSelected && !nextSelected) {
view.announceForAccessibility(
view.getContext().getString(R.string.state_unselected_description));
}
} else {
view.setSelected(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
name="state_collapsed_description"
translatable="false"
>collapsed</string>
<string
name="state_unselected_description"
translatable="false"
>unselected</string>
<string
name="state_on_description"
translatable="false"
Expand Down

0 comments on commit 73bc96e

Please sign in to comment.