Skip to content

Commit 26502c6

Browse files
rozelemeta-codesync[bot]
authored andcommitted
Do not scroll to child inside nested scroll view (facebook#54044)
Summary: Pull Request resolved: facebook#54044 In rare cases, there may be a vertical ScrollView nested inside another vertical ScrollView. In these cases, when the requestChildFocus method is called, we may attempt to bring the entire focused child into view. However, we really only want to bring the entire nested ScrollView into view. ## Changelog [Android][Fixed] Focused scroll into view behaviors for nested vertical scroll views Reviewed By: bvanderhoof Differential Revision: D83804043 fbshipit-source-id: 8df8f637e7f908cc283f55c0d78ee03ed3bb9117
1 parent aab0d33 commit 26502c6

File tree

1 file changed

+15
-2
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,24 @@ public boolean isPartiallyScrolledInView(View descendent) {
528528
}
529529

530530
private void scrollToChild(View child) {
531+
// Only scroll the nearest ReactScrollView ancestor into view, rather than the focused child.
532+
// Nested ScrollView instances will handle scrolling the child into their respective viewports.
533+
View parent = child;
534+
View scrollViewAncestor = null;
535+
while (parent != null && parent != this) {
536+
if (parent instanceof ReactScrollView) {
537+
scrollViewAncestor = parent;
538+
}
539+
parent = (View) parent.getParent();
540+
}
541+
542+
View scrollIntoViewTarget = scrollViewAncestor != null ? scrollViewAncestor : child;
543+
531544
Rect tempRect = new Rect();
532-
child.getDrawingRect(tempRect);
545+
scrollIntoViewTarget.getDrawingRect(tempRect);
533546

534547
/* Offset from child's local coordinates to ScrollView coordinates */
535-
offsetDescendantRectToMyCoords(child, tempRect);
548+
offsetDescendantRectToMyCoords(scrollIntoViewTarget, tempRect);
536549

537550
int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(tempRect);
538551

0 commit comments

Comments
 (0)