Skip to content

Commit 70fcab7

Browse files
blavallafacebook-github-bot
authored andcommitted
Fix RN accessibility links with UIAutomator
Summary: D34687371 (7b5b114) unfortunately caused a regression with UIAutomator, where it would no longer be able to see any Views that have the ReactAccessibilityDelegate attached to them. This was because the delegate was changed to extend ExploreByTouchHelper which implements its own default AccessibilityNodeProvider, which does nothing in the case of a view without any virtual children. This diff simply *only* uses the node provider if the view in question has virtual children, otherwise defaulting to the standard behavior from the View class. Changelog: [Android][Fixed] - Fixed issue where any node with an AccessibilityDelegate set (which was any node with any accessibility propoerty), was using ExploreByTouchHelper's built in AccessibilityNodeProvider, and not properly populating their AccessibilityNodeInfo's, leading to focus issues and issues with automated test services like UIAutomator. Reviewed By: kacieb Differential Revision: D35601320 fbshipit-source-id: 92e009c6e8b4ddcab860e2c91e6bd1a8f95359f0
1 parent f8dee0e commit 70fcab7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java

+17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
2828
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;
2929
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.RangeInfoCompat;
30+
import androidx.core.view.accessibility.AccessibilityNodeProviderCompat;
3031
import androidx.customview.widget.ExploreByTouchHelper;
3132
import com.facebook.react.R;
3233
import com.facebook.react.bridge.Arguments;
@@ -684,4 +685,20 @@ private static class AccessibleLink {
684685
public int id;
685686
}
686687
}
688+
689+
@Override
690+
public @Nullable AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host) {
691+
// Only set a NodeProvider if we have virtual views, otherwise just return null here so that
692+
// we fall back to the View class's default behavior. If we don't do this, then Views with
693+
// no virtual children will fall back to using ExploreByTouchHelper's onPopulateNodeForHost
694+
// method to populate their AccessibilityNodeInfo, which defaults to doing nothing, so no
695+
// AccessibilityNodeInfo will be created. Alternatively, we could override
696+
// onPopulateNodeForHost instead, and have it create an AccessibilityNodeInfo for the host
697+
// but this is what the default View class does by itself, so we may as well defer to it.
698+
if (mAccessibilityLinks != null) {
699+
return super.getAccessibilityNodeProvider(host);
700+
}
701+
702+
return null;
703+
}
687704
}

0 commit comments

Comments
 (0)