Skip to content

Commit

Permalink
add talkback navigation for links and header
Browse files Browse the repository at this point in the history
1. add role description for heading
2. add talkback navigation support for link and header
  • Loading branch information
Wei Yang committed Feb 21, 2019
1 parent 5360452 commit 955cce6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat.CollectionItemInfoCompat;
import android.text.SpannableString;
import android.text.style.URLSpan;
import android.view.View;
import com.facebook.react.R;
import java.util.Locale;
Expand Down Expand Up @@ -98,7 +101,6 @@ public static void setDelegate(final View view) {
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
setRole(info, accessibilityRole, view.getContext());
if (!(accessibilityHint == null)) {
String contentDescription=(String)info.getContentDescription();
if (contentDescription != null) {
Expand All @@ -108,6 +110,8 @@ public void onInitializeAccessibilityNodeInfo(
info.setContentDescription(accessibilityHint);
}
}

setRole(info, accessibilityRole, view.getContext());
}
});
}
Expand All @@ -127,6 +131,18 @@ public static void setRole(AccessibilityNodeInfoCompat nodeInfo, AccessibilityRo
if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
if (role.equals(AccessibilityRole.LINK)) {
nodeInfo.setRoleDescription(context.getString(R.string.link_description));

if (nodeInfo.getContentDescription() != null) {
SpannableString spannable = new SpannableString(nodeInfo.getContentDescription());
spannable.setSpan(new URLSpan(""), 0, spannable.length(), 0);
nodeInfo.setContentDescription(spannable);
}

if (nodeInfo.getText() != null) {
SpannableString spannable = new SpannableString(nodeInfo.getText());
spannable.setSpan(new URLSpan(""), 0, spannable.length(), 0);
nodeInfo.setText(spannable);
}
}
if (role.equals(AccessibilityRole.SEARCH)) {
nodeInfo.setRoleDescription(context.getString(R.string.search_description));
Expand All @@ -140,6 +156,15 @@ public static void setRole(AccessibilityNodeInfoCompat nodeInfo, AccessibilityRo
if (role.equals(AccessibilityRole.ADJUSTABLE)) {
nodeInfo.setRoleDescription(context.getString(R.string.adjustable_description));
}
if (role.equals(AccessibilityRole.HEADER)) {
nodeInfo.setRoleDescription(context.getString(R.string.header_description));

final AccessibilityNodeInfoCompat.CollectionItemInfoCompat itemInfo =
AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
0, 1, 0, 1,
true);
nodeInfo.setCollectionItemInfo(itemInfo);
}
}
if (role.equals(AccessibilityRole.IMAGEBUTTON)) {
nodeInfo.setClickable(true);
Expand Down
4 changes: 4 additions & 0 deletions ReactAndroid/src/main/res/views/uimanager/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
name="adjustable_description"
translatable="false"
>Adjustable</string>
<string
name="header_description"
translatable="false"
>Heading</string>
</resources>

0 comments on commit 955cce6

Please sign in to comment.