Skip to content

Commit

Permalink
Fix issue with scrollTo method in ScrollViews to set actual scroll po…
Browse files Browse the repository at this point in the history
…sition

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
  • Loading branch information
ryancat authored and facebook-github-bot committed Oct 9, 2021
1 parent 2a605c3 commit 1a9e2d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,12 @@ 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,12 @@ public void onAnimationRepeat(Animator animator) {}
@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);
}

/**
Expand Down

0 comments on commit 1a9e2d5

Please sign in to comment.