Permalink
Browse files

Added logic to only override role description that is said on TalkBac…

…k if it's in english.

Summary:
Context:
On Android, I am currently overriding the role description for TalkBack on certain Roles. Currently, these are done only in English.
I needed to add a checker that only overrides these role descriptions if the language of the phone is set

Changes:
* Added a language checker before I call setRoleDescription
* Put the strings into variables.

Note:
This is done to prioritize a codemod for accessibilityRole. Eventually, we hope to add support for other languages on these roles.

Reviewed By: blavalla

Differential Revision: D8884991

fbshipit-source-id: 3182eb5856ea57939fb25b17522d4b79ef2078e3
  • Loading branch information...
ziqichen6 authored and facebook-github-bot committed Jul 24, 2018
1 parent dfcf9c5 commit 9f01e4ccffbcbbb0683ffadef03aa4c2f116fd53
@@ -6,13 +6,16 @@
package com.facebook.react.uimanager;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray;
import java.util.Locale;
import javax.annotation.Nullable;
/**
@@ -32,7 +35,7 @@
public enum AccessibilityRole {
NONE(null),
BUTTON("android.widget.Button"),
LINK("android.widget.Button"),
LINK("android.widget.ViewGroup"),
SEARCH("android.widget.EditText"),
IMAGE("android.widget.ImageView"),
IMAGEBUTTON("android.widget.ImageView"),
@@ -65,7 +68,7 @@ private AccessibilityRoleUtil() {
// No instances
}
public static void setRole(View view, final AccessibilityRole role) {
public static void setRole(final View view, final AccessibilityRole role) {
// if a view already has an accessibility delegate, replacing it could cause problems,
// so leave it alone.
if (!ViewCompat.hasAccessibilityDelegate(view)) {
@@ -76,32 +79,42 @@ public static void setRole(View view, final AccessibilityRole role) {
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
setRole(info, role);
setRole(info, role, view.getContext());
}
});
}
}
public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role) {
/**
* Strings for setting the Role Description in english
*/
//TODO: Eventually support fot other languages on talkback
public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role, final Context context) {
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 (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
if (role.equals(AccessibilityRole.LINK)) {
nodeInfo.setRoleDescription(context.getString(R.string.link_description));
}
if (role.equals(AccessibilityRole.SEARCH)) {
nodeInfo.setRoleDescription(context.getString(R.string.search_description));
}
if (role.equals(AccessibilityRole.IMAGE)) {
nodeInfo.setRoleDescription(context.getString(R.string.image_description));
}
if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
nodeInfo.setRoleDescription(context.getString(R.string.image_button_description));
}
if (role.equals(AccessibilityRole.ADJUSTABLE)) {
nodeInfo.setRoleDescription(context.getString(R.string.adjustable_description));
}
}
if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
nodeInfo.setRoleDescription("Button Image");
nodeInfo.setClickable(true);
}
if (role.equals(AccessibilityRole.ADJUSTABLE)) {
nodeInfo.setRoleDescription("Adjustable");
}
}
/**
* Method for setting accessibilityRole on view properties.
*/
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="link_description"
>Link</string>
<string
name="search_description"
>Search Field</string>
<string
name="image_description"
>Image</string>
<string
name="image_button_description"
>Button, Image</string>
<string
name="adjustable_description"
>Adjustable</string>
</resources>

0 comments on commit 9f01e4c

Please sign in to comment.