Skip to content

Commit

Permalink
Applied facebook#15670 - contentOffset validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nixoz committed Sep 15, 2017
1 parent 641a08f commit b820614
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions React/Views/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,16 @@ - (void)setFrame:(CGRect)frame
contentSize.width + contentInset.left + contentInset.right,
contentSize.height + contentInset.top + contentInset.bottom);

CGSize boundsSize = self.bounds.size;

self.contentOffset = CGPointMake(
MAX(0, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)),
MAX(0, MIN(originalOffset.y, fullContentSize.height - boundsSize.height)));
// If contentSize has not been measured yet we can't check bounds.
if (CGSizeEqualToSize(contentSize, CGSizeZero)) {
self.contentOffset = originalOffset;
} else {
// Make sure offset don't exceed bounds. This could happen on screen rotation.
CGSize boundsSize = self.bounds.size;
self.contentOffset = CGPointMake(
MAX(-contentInset.left, MIN(contentSize.width - boundsSize.width + contentInset.right, originalOffset.x)),
MAX(-contentInset.top, MIN(contentSize.height - boundsSize.height + contentInset.bottom, originalOffset.y)));
}
}

#if !TARGET_OS_TV
Expand Down

0 comments on commit b820614

Please sign in to comment.