-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IOS][BUGFIX] Fix: Added scroll Bounds check in scrollToOffset method in RCTScrollView on iOS #17927
[IOS][BUGFIX] Fix: Added scroll Bounds check in scrollToOffset method in RCTScrollView on iOS #17927
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,6 +577,23 @@ - (void)scrollToOffset:(CGPoint)offset | |
- (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated | ||
{ | ||
if (!CGPointEqualToPoint(_scrollView.contentOffset, offset)) { | ||
BOOL isHorizontal = [self isHorizontal:_scrollView]; | ||
if (isHorizontal) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should we have this condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shergin Updated PR to handle offset range in single expression. |
||
CGFloat offsetX = _scrollView.contentSize.width - _scrollView.bounds.size.width + _scrollView.contentInset.right; | ||
if(offset.x > offsetX) { | ||
offset = CGPointMake(fmax(offsetX, 0), 0); | ||
} else if(offset.x < 0) { | ||
offset = CGPointMake(0, 0); | ||
} | ||
} else { | ||
CGFloat offsetY = _scrollView.contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom; | ||
if(offset.y > offsetY) { | ||
offset = CGPointMake(0, fmax(offsetY, 0)); | ||
} else if(offset.y < 0) { | ||
offset = CGPointMake(0, 0); | ||
} | ||
} | ||
|
||
// Ensure at least one scroll event will fire | ||
_allowNextScrollNoMatterWhat = YES; | ||
[_scrollView setContentOffset:offset animated:animated]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow existing code style guides.