Skip to content

Commit 8184ed6

Browse files
jorge-cabfacebook-github-bot
authored andcommitted
Add OnHierarchyChangeListener to accessibilityOrder parent to track changes in hierarchy (facebook#50261)
Summary: Pull Request resolved: facebook#50261 Since now we have the optimization of only running the custom accessibility order when we define the tree as dirty we need to add a hierarchy change listener on all ViewGroups within the parent to notify accessibility services of potential changes in hierarchy and so mark the subtree as dirty. Changelog: [Internal] Reviewed By: joevilches Differential Revision: D71821636 fbshipit-source-id: 25649efa1679024a205e94c340511dc58783d575
1 parent 8cf4d5b commit 8184ed6

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,31 @@ public void setAccessibilityOrder(@NonNull T view, @Nullable ReadableArray nativ
307307
view.setTag(R.id.accessibility_order, nativeIds);
308308
view.setTag(R.id.accessibility_order_dirty, true);
309309

310+
if (view instanceof ViewGroup) {
311+
((ViewGroup) view)
312+
.setOnHierarchyChangeListener(
313+
new ViewGroup.OnHierarchyChangeListener() {
314+
@Override
315+
public void onChildViewAdded(View parent, View child) {
316+
view.setTag(R.id.accessibility_order_dirty, true);
317+
318+
// We also want to listen to changes on the hierarchy of nested ViewGroups
319+
if (child instanceof ViewGroup) {
320+
ViewGroup childGroup = (ViewGroup) child;
321+
childGroup.setOnHierarchyChangeListener(this);
322+
for (int i = 0; i < childGroup.getChildCount(); i++) {
323+
onChildViewAdded(childGroup, childGroup.getChildAt(i));
324+
}
325+
}
326+
}
327+
328+
@Override
329+
public void onChildViewRemoved(View parent, View child) {
330+
view.setTag(R.id.accessibility_order_dirty, true);
331+
}
332+
});
333+
}
334+
310335
ReactAxOrderHelper.unsetAccessibilityOrder(view);
311336
((ViewGroup) view)
312337
.notifySubtreeAccessibilityStateChanged(

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
142142
boolean isAxOrderDirty = (boolean) host.getTag(R.id.accessibility_order_dirty);
143143
if (isAxOrderDirty) {
144144
ReactAxOrderHelper.setCustomAccessibilityFocusOrder(host);
145-
host.setTag(R.id.accessibility_order_dirty);
145+
host.setTag(R.id.accessibility_order_dirty, false);
146146
}
147147
}
148148

packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- tag is used to store the accessibleElements tag -->
1010
<item type="id" name="accessibility_order"/>
1111

12-
<!-- tag is used to store the accessibleElements tag -->
12+
<!-- tag is used to store the current state of the accessibility order tree-->
1313
<item type="id" name="accessibility_order_dirty"/>
1414

1515
<!-- tag is used to store the accessibleElements parent View tag -->

0 commit comments

Comments
 (0)