Skip to content

Commit

Permalink
Simplify Accessibility Heading role for React Native (Android)
Browse files Browse the repository at this point in the history
Summary:
The previous approach to set a heading in Android required us to trick the accessibility service into thinking that this element was the heading inside of a list, which used to be the only place you could use headings on Android.

This worked for the most part, but could cause problems in specific circumstances, such as if that element actually *was* part of a list. Since we were overriding its CollectionItemInfo, and presenting it as the first item in a single column list, the parent list could have confusing announcements such as announcing this item as "Item 1" even if it was not the first item in the actual list.

Since API 28, there has been an API to set any view as a heading (https://developer.android.com/reference/android/view/View#setAccessibilityHeading(boolean)).

This switches our implementation to use this new API via the AccessibilityNodeInfoCompat class for backwards compatibility to older API versions.

Changelog:
[Android][Changed] - Simplify Accessibility Heading role implementation.

Differential Revision: D39076827

fbshipit-source-id: 583dc1e9d2779a4efa5f98cabef506df2770d892
  • Loading branch information
blavalla authored and facebook-github-bot committed Sep 20, 2022
1 parent 010da67 commit 353b1b0
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,7 @@ public static void setRole(
} else if (role.equals(AccessibilityRole.SUMMARY)) {
nodeInfo.setRoleDescription(context.getString(R.string.summary_description));
} else if (role.equals(AccessibilityRole.HEADER)) {
final AccessibilityNodeInfoCompat.CollectionItemInfoCompat itemInfo =
AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(0, 1, 0, 1, true);
nodeInfo.setCollectionItemInfo(itemInfo);
nodeInfo.setHeading(true);
} else if (role.equals(AccessibilityRole.ALERT)) {
nodeInfo.setRoleDescription(context.getString(R.string.alert_description));
} else if (role.equals(AccessibilityRole.COMBOBOX)) {
Expand Down

0 comments on commit 353b1b0

Please sign in to comment.