mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2a605c30e4
commit
1a9e2d5d55
+6
-2
@@ -1231,8 +1231,12 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
}
|
||||
|
||||
super.scrollTo(x, y);
|
||||
updateStateOnScroll(x, y);
|
||||
setPendingContentOffsets(x, y);
|
||||
// The final scroll position might be different from (x, y). For example, we may need to scroll
|
||||
// to the last item in the list, but that item cannot be move to the start position of the view.
|
||||
final int actualX = getScrollX();
|
||||
final int actualY = getScrollY();
|
||||
updateStateOnScroll(actualX, actualY);
|
||||
setPendingContentOffsets(actualX, actualY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1006,8 +1006,12 @@ public class ReactScrollView extends ScrollView
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
updateStateOnScroll(x, y);
|
||||
setPendingContentOffsets(x, y);
|
||||
// The final scroll position might be different from (x, y). For example, we may need to scroll
|
||||
// to the last item in the list, but that item cannot be move to the start position of the view.
|
||||
final int actualX = getScrollX();
|
||||
final int actualY = getScrollY();
|
||||
updateStateOnScroll(actualX, actualY);
|
||||
setPendingContentOffsets(actualX, actualY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user