Skip to content

Commit

Permalink
Fix autoscrollToTopThreshold on iOS old arch (#38245)
Browse files Browse the repository at this point in the history
Summary:
Currently `autoscrollToTopThreshold` does not work correctly, it will scroll to top even when the scroll position is past the `autoscrollToTopThreshold` value.

The value of x/y is taken before we adjust the scroll position so we do not need to subtract the delta.

Note that this was already fixed when I ported this code to fabric, so this fix is only needed in the old arch code.

bypass-github-export-checks

## Changelog:

[IOS] [FIXED] - Fix autoscrollToTopThreshold on iOS old arch

Pull Request resolved: #38245

Test Plan:
In RNTester example, threshold is set to 10, so it should not scroll to top if we are further than 10px from the top of the list.

Before:

https://github.com/facebook/react-native/assets/2677334/13723787-1bc4-4263-9bcb-91ddf7454de3

After:

https://github.com/facebook/react-native/assets/2677334/a8cfdaac-59fc-40de-970a-ff992366e25f

Reviewed By: rshest

Differential Revision: D50447644

Pulled By: cipolleschi

fbshipit-source-id: b21f1836db293120a7a795c8f8f6dd54887495a7
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Oct 24, 2023
1 parent 31cf4c4 commit 9666814
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ - (void)uiManagerWillPerformMounting:(RCTUIManager *)manager
CGPointMake(self->_scrollView.contentOffset.x + deltaX, self->_scrollView.contentOffset.y);
if (autoscrollThreshold != nil) {
// If the offset WAS within the threshold of the start, animate to the start.
if (x - deltaX <= [autoscrollThreshold integerValue]) {
if (x <= [autoscrollThreshold integerValue]) {
[self scrollToOffset:CGPointMake(-leftInset, self->_scrollView.contentOffset.y) animated:YES];
}
}
Expand All @@ -988,7 +988,7 @@ - (void)uiManagerWillPerformMounting:(RCTUIManager *)manager
CGPointMake(self->_scrollView.contentOffset.x, self->_scrollView.contentOffset.y + deltaY);
if (autoscrollThreshold != nil) {
// If the offset WAS within the threshold of the start, animate to the start.
if (y - deltaY <= [autoscrollThreshold integerValue]) {
if (y <= [autoscrollThreshold integerValue]) {
[self scrollToOffset:CGPointMake(self->_scrollView.contentOffset.x, -bottomInset) animated:YES];
}
}
Expand Down

0 comments on commit 9666814

Please sign in to comment.