From e7391438093cd5dd5033204cdce62e66509e66e1 Mon Sep 17 00:00:00 2001 From: Ziqi Chen Date: Thu, 12 Jul 2018 23:35:57 -0700 Subject: [PATCH] added in the three roles: search, adjustable, link that require localization Summary: Added the android functionality for those three roles: search, adjustable, and link. Until React Native internal framework ports internationalization and localization of strings, I'll handle localization by allowing an extra prop to be passed in that can override talkback's description in another language if needed. Reviewed By: blavalla Differential Revision: D8807692 fbshipit-source-id: b51877d187cb6cb663d65d6b4d072e6dc52a2d03 --- .../uimanager/AccessibilityRoleUtil.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) 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 1635f6045..86095befc 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 class AccessibilityRoleUtil { 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); } } }