Skip to content

Commit

Permalink
Fix scrollview over bounds of content size (facebook#23427)
Browse files Browse the repository at this point in the history
Summary:
Fix scrollview `offset` out of content size in iOS, Android uses `scrollTo` and `smoothScrollTo` which not have this issue.

Fixes like facebook#13594 facebook#22768 facebook#19970 .

[iOS] [Fixed] - Fixed scrollView offset out of content size.
Pull Request resolved: facebook#23427

Differential Revision: D14162663

Pulled By: cpojer

fbshipit-source-id: a95371c8d703b6d5f604af0072f86c01c2018f4a
  • Loading branch information
zhongwuzw authored and Martynas Bardauskas committed Feb 21, 2019
1 parent 2f42c06 commit 796b99a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,19 @@ - (void)scrollToOffset:(CGPoint)offset
- (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated
{
if (!CGPointEqualToPoint(_scrollView.contentOffset, offset)) {
CGRect maxRect = CGRectMake(fmin(-_scrollView.contentInset.left, 0),
fmin(-_scrollView.contentInset.top, 0),
fmax(_scrollView.contentSize.width - _scrollView.bounds.size.width + _scrollView.contentInset.right + fmax(_scrollView.contentInset.left, 0), 0.01),
fmax(_scrollView.contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom + fmax(_scrollView.contentInset.top, 0), 0.01)); // Make width and height greater than 0
// Ensure at least one scroll event will fire
_allowNextScrollNoMatterWhat = YES;
if (!CGRectContainsPoint(maxRect, offset)) {
CGFloat x = fmax(offset.x, CGRectGetMinX(maxRect));
x = fmin(x, CGRectGetMaxX(maxRect));
CGFloat y = fmax(offset.y, CGRectGetMinY(maxRect));
y = fmin(y, CGRectGetMaxY(maxRect));
offset = CGPointMake(x, y);
}
[_scrollView setContentOffset:offset animated:animated];
}
}
Expand Down

0 comments on commit 796b99a

Please sign in to comment.