diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java index 29292c7e16ea2e..7db489a0bc564c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java @@ -191,6 +191,15 @@ public static AccessibilityRole fromValue(@Nullable String value) { } throw new IllegalArgumentException("Invalid accessibility role value: " + value); } + + public static @Nullable String fromAnyValue(@Nullable String value) { + for (AccessibilityRole role : AccessibilityRole.values()) { + if (getValue(role).equalsIgnoreCase(value)) { + return role.toString(); + } + } + return null; + } } private final HashMap mAccessibilityActionsMap; @@ -304,8 +313,11 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo if (testId != null) { info.setViewIdResourceName(testId); } - boolean missingTextOrDescription = - info.getText() == null && info.getContentDescription() == null; + // need to check that string length is not == 0 + boolean missingContentDescription = TextUtils.isEmpty(info.getContentDescription()); + boolean missingText = TextUtils.isEmpty(info.getText()); + boolean missingTextOrDescription = missingContentDescription && missingText; + // add check on placeholder boolean hasContentToAnnounce = accessibilityActions != null || accessibilityState != null @@ -963,6 +975,20 @@ private static void addStateSegments( } } + public static @Nullable String getRoleDescription(AccessibilityNodeInfoCompat node) { + CharSequence role = node.getRoleDescription(); + String roleDescription; + + if (role == null || role == "") { + roleDescription = + ReactAccessibilityDelegate.AccessibilityRole.fromAnyValue((String) node.getClassName()); + } else { + roleDescription = role.toString(); + } + + return roleDescription; + } + /** * Creates the text that Google's TalkBack screen reader will read aloud for a given {@link View}. * This may be any combination of the {@link View}'s {@code text}, {@code contentDescription}, and @@ -994,7 +1020,7 @@ public static CharSequence getTalkbackDescription( final boolean hasNodeText = !TextUtils.isEmpty(nodeText); final boolean isEditText = view instanceof EditText; - CharSequence roleDescription = node.getRoleDescription(); + String roleDescription = getRoleDescription(node); // The original flipper implementation would check isActionableForAccessibility // The check was removed for this reason https://bit.ly/3wPnmPE boolean disabled = !node.isEnabled(); @@ -1037,8 +1063,7 @@ public static CharSequence getTalkbackDescription( // role if (roleDescription != null) { - String roleString = roleDescription.toString(); - talkbackSegments.append(roleString + delimiter); + talkbackSegments.append(roleDescription + delimiter); } // disabled diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index a8737f7d383410..69a7e7296bfa14 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -281,16 +281,21 @@ class AccessibilityExample extends React.Component<{}> { - - - + + Text number 1 + + + + + );