diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityRoleUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityRoleUtil.java index 1635f604596be0..86095befc24f4c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityRoleUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/AccessibilityRoleUtil.java @@ -31,9 +31,12 @@ public class AccessibilityRoleUtil { public enum AccessibilityRole { NONE(null), BUTTON("android.widget.Button"), + LINK("android.widget.Button"), + SEARCH("android.widget.EditText"), IMAGE("android.widget.ImageView"), - KEYBOARD_KEY("android.inputmethodservice.Keyboard$Key"), - TEXT("android.widget.ViewGroup"); + KEYBOARDKEY("android.inputmethodservice.Keyboard$Key"), + TEXT("android.widget.ViewGroup"), + ADJUSTABLE("android.widget.SeekBar"); @Nullable private final String mValue; @@ -79,38 +82,33 @@ public void onInitializeAccessibilityNodeInfo( public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role) { nodeInfo.setClassName(role.getValue()); + if (role.equals(AccessibilityRole.LINK)) { + nodeInfo.setRoleDescription("Link"); + } + if (role.equals(AccessibilityRole.SEARCH)) { + nodeInfo.setRoleDescription("Search Field"); + } + if (role.equals(AccessibilityRole.IMAGE)) { + nodeInfo.setRoleDescription("Image"); + } + if (role.equals(AccessibilityRole.ADJUSTABLE)) { + nodeInfo.setRoleDescription("Adjustable"); + } } - + /** * Variables and methods for setting accessibilityRole on view properties. */ - private static final String NONE = "none"; - private static final String BUTTON = "button"; - private static final String IMAGE = "image"; - private static final String KEYBOARDKEY = "keyboardkey"; - private static final String TEXT = "text"; - public static void updateAccessibilityRole(View view, String role) { if (role == null) { view.setAccessibilityDelegate(null); } - switch (role) { - case NONE: - break; - case BUTTON: - setRole(view, AccessibilityRoleUtil.AccessibilityRole.BUTTON); - break; - case IMAGE: - setRole(view, AccessibilityRoleUtil.AccessibilityRole.IMAGE); - break; - case KEYBOARDKEY: - setRole(view, AccessibilityRoleUtil.AccessibilityRole.KEYBOARD_KEY); - break; - case TEXT: - setRole(view, AccessibilityRoleUtil.AccessibilityRole.TEXT); - break; - default: - view.setAccessibilityDelegate(null); + try { + setRole(view, AccessibilityRole.valueOf(role.toUpperCase())); + } catch (NullPointerException e) { + view.setAccessibilityDelegate(null); + } catch (IllegalArgumentException e) { + view.setAccessibilityDelegate(null); } } }