Skip to content

Commit

Permalink
Fix default accessibility delegate
Browse files Browse the repository at this point in the history
Summary:
The current accessibility implementation tries to generalize every view's accessibility node info by setting an accessibility delegate on every view -- regardless of whether or not any accessibility properties are set. This delegate however doesn't correctly set the appropriate accessibility node fields for every view. For example, ScrollViews needs AccessibilityNode.setScrollable(true) set, but the generic delegate does not account for this. For now let's avoid unnecessarily
setting an accessibility delegate on views that don't have any accessibility props set, which will likely fix the majority of these issues.

Reviewed By: mdvacca

Differential Revision: D10138128

fbshipit-source-id: b999b41e7256e3dce94cd70e9b944979d52f74fd
  • Loading branch information
ayc1 authored and facebook-github-bot committed Oct 2, 2018
1 parent 637d74f commit d3f2f96
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,20 @@ private AccessibilityDelegateUtil() {
}

public static void setDelegate(final View view) {
final String accessibilityHint = (String) view.getTag(R.id.accessibility_hint);
final AccessibilityRole accessibilityRole = (AccessibilityRole) view.getTag(R.id.accessibility_role);
// if a view already has an accessibility delegate, replacing it could cause problems,
// so leave it alone.
if (!ViewCompat.hasAccessibilityDelegate(view)) {
if (!ViewCompat.hasAccessibilityDelegate(view) &&
accessibilityHint != null &&
accessibilityRole != null) {
ViewCompat.setAccessibilityDelegate(
view,
new AccessibilityDelegateCompat() {
@Override
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfoCompat info) {
super.onInitializeAccessibilityNodeInfo(host, info);
String accessibilityHint = (String) view.getTag(R.id.accessibility_hint);
AccessibilityRole accessibilityRole = (AccessibilityRole) view.getTag(R.id.accessibility_role);
if (accessibilityRole == null) {
accessibilityRole = AccessibilityRole.NONE;
}
setRole(info, accessibilityRole, view.getContext());
if (!(accessibilityHint == null)) {
String contentDescription=(String)info.getContentDescription();
Expand All @@ -103,7 +102,10 @@ public void onInitializeAccessibilityNodeInfo(

//TODO: Eventually support for other languages on talkback

public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role, final Context context) {
public static void setRole(AccessibilityNodeInfoCompat nodeInfo, AccessibilityRole role, final Context context) {
if (role == null) {
role = AccessibilityRole.NONE;
}
nodeInfo.setClassName(role.getValue());
if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
if (role.equals(AccessibilityRole.LINK)) {
Expand Down

0 comments on commit d3f2f96

Please sign in to comment.