Skip to content

Commit a460df2

Browse files
jgryko5meta-codesync[bot]
authored andcommitted
Fix keyboard navigation through nested a11y views in ReactHorizontalScrollView with snapToInterval enabled (#54351)
Summary: Pull Request resolved: #54351 Navigating with keyboard through a11y items in horizontal FlatList that are not the direct child of the ScrollView contentView is broken, because instead of focusing the next focusable sibling, arrowScroll scrolls to the next page. This issue only happens when FlatList has snapToInterval enabled. Fixed the condition that checked if a given focusable view belongs to the contentView. Changelog: [Android] [Fixed] - Fix keyboard navigation through items in horizontal ScrollView with snapToInterval enabled Reviewed By: Abbondanzo Differential Revision: D85261167 fbshipit-source-id: 220c6648c0381899f312b1b1f3923ed5203899b1
1 parent 1ffa38d commit a460df2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.view.MotionEvent;
2929
import android.view.View;
3030
import android.view.ViewGroup;
31+
import android.view.ViewParent;
3132
import android.view.accessibility.AccessibilityNodeInfo;
3233
import android.widget.HorizontalScrollView;
3334
import android.widget.OverScroller;
@@ -740,6 +741,20 @@ public boolean pageScroll(int direction) {
740741
return handled;
741742
}
742743

744+
private boolean isDescendantOf(View parent, View view) {
745+
if (view == null || parent == null) {
746+
return false;
747+
}
748+
ViewParent p = view.getParent();
749+
while (p != null && p.getParent() != null) {
750+
if (p == parent) {
751+
return true;
752+
}
753+
p = p.getParent();
754+
}
755+
return false;
756+
}
757+
743758
@Override
744759
public boolean arrowScroll(int direction) {
745760
boolean handled = false;
@@ -751,7 +766,7 @@ public boolean arrowScroll(int direction) {
751766
View currentFocused = findFocus();
752767
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
753768
View rootChild = getContentView();
754-
if (rootChild != null && nextFocused != null && nextFocused.getParent() == rootChild) {
769+
if (isDescendantOf(rootChild, nextFocused)) {
755770
if (!isScrolledInView(nextFocused) && !isMostlyScrolledInView(nextFocused)) {
756771
smoothScrollToNextPage(direction);
757772
}

0 commit comments

Comments
 (0)