mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix scrollview over bounds of content size (#23427)
Summary: Fix scrollview `offset` out of content size in iOS, Android uses `scrollTo` and `smoothScrollTo` which not have this issue. Fixes like #13594 #22768 #19970 . [iOS] [Fixed] - Fixed scrollView offset out of content size. Pull Request resolved: https://github.com/facebook/react-native/pull/23427 Differential Revision: D14162663 Pulled By: cpojer fbshipit-source-id: a95371c8d703b6d5f604af0072f86c01c2018f4a
This commit is contained in:
committed by
Mike Grabowski
parent
699fad7d06
commit
f6516d20ca
@@ -588,8 +588,19 @@ static inline void RCTApplyTransformationAccordingLayoutDirection(UIView *view,
|
||||
- (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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user