Skip to content

Commit b820614

Browse files
committed
Applied facebook#15670 - contentOffset validation
facebook#15670
1 parent 641a08f commit b820614

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

React/Views/RCTScrollView.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,16 @@ - (void)setFrame:(CGRect)frame
314314
contentSize.width + contentInset.left + contentInset.right,
315315
contentSize.height + contentInset.top + contentInset.bottom);
316316

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

324329
#if !TARGET_OS_TV

0 commit comments

Comments
 (0)