Skip to content

Commit 1a9e2d5

Browse files
ryancatfacebook-github-bot
authored andcommitted
Fix issue with scrollTo method in ScrollViews to set actual scroll position
Summary: The `scrollTo` method in ScrollViews are using the `(x, y)` position they got from upperstream to scroll, and to set the state for Fabric. This diff fixes an edge case where the scroll result is not ended up to `(x, y)`. For example, if we are going to scroll to the last item in the list, the item may not scroll to the `(x, y)` position, but stay at the end position of the view. - Change `scrollTo` method to use the actual `scrollX` and `scrollY` position after scrolling to set current state. Changelog: [Android][Fixed] - scrollTo API in ScrollView will check the actual scroll position before setting the scroll state Reviewed By: JoshuaGross Differential Revision: D31492685 fbshipit-source-id: e5513fb735ea68c5014b5c47fadffe461cad5c94
1 parent 2a605c3 commit 1a9e2d5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,12 @@ public void scrollTo(int x, int y) {
12311231
}
12321232

12331233
super.scrollTo(x, y);
1234-
updateStateOnScroll(x, y);
1235-
setPendingContentOffsets(x, y);
1234+
// The final scroll position might be different from (x, y). For example, we may need to scroll
1235+
// to the last item in the list, but that item cannot be move to the start position of the view.
1236+
final int actualX = getScrollX();
1237+
final int actualY = getScrollY();
1238+
updateStateOnScroll(actualX, actualY);
1239+
setPendingContentOffsets(actualX, actualY);
12361240
}
12371241

12381242
/**

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,12 @@ public void onAnimationRepeat(Animator animator) {}
10061006
@Override
10071007
public void scrollTo(int x, int y) {
10081008
super.scrollTo(x, y);
1009-
updateStateOnScroll(x, y);
1010-
setPendingContentOffsets(x, y);
1009+
// The final scroll position might be different from (x, y). For example, we may need to scroll
1010+
// to the last item in the list, but that item cannot be move to the start position of the view.
1011+
final int actualX = getScrollX();
1012+
final int actualY = getScrollY();
1013+
updateStateOnScroll(actualX, actualY);
1014+
setPendingContentOffsets(actualX, actualY);
10111015
}
10121016

10131017
/**

0 commit comments

Comments
 (0)