Skip to content

Commit

Permalink
Fixed ScrollView adjust inset behavior (#23555)
Browse files Browse the repository at this point in the history
Summary:
Fixes #23500 , if user set prop `contentInsetAdjustmentBehavior="automatic"` of ScrollView, it not works when initial on the screen. We fixes it by filter valid offset, if offset is valid, just return.

[iOS] [Fixed] - Fixed ScrollView adjust inset behavior
Pull Request resolved: #23555

Differential Revision: D14161593

Pulled By: cpojer

fbshipit-source-id: 01434e55106ffde7f8e39f66dd5b0f02df9b38b1
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Feb 21, 2019
1 parent 5360452 commit 2ea4bcd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,22 @@ - (void)setFrame:(CGRect)frame
if (CGSizeEqualToSize(contentSize, CGSizeZero)) {
self.contentOffset = originalOffset;
} else {
// Make sure offset don't exceed bounds. This could happen on screen rotation.
if (@available(iOS 11.0, *)) {
if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, self.adjustedContentInset)) {
contentInset = self.adjustedContentInset;
}
}
CGSize boundsSize = self.bounds.size;
CGFloat xMaxOffset = contentSize.width - boundsSize.width + contentInset.right;
CGFloat yMaxOffset = contentSize.height - boundsSize.height + contentInset.bottom;
// Make sure offset doesn't exceed bounds. This can happen on screen rotation.
if ((originalOffset.x >= -contentInset.left) && (originalOffset.x <= xMaxOffset) &&
(originalOffset.y >= -contentInset.top) && (originalOffset.y <= yMaxOffset)) {
return;
}
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)));
MAX(-contentInset.left, MIN(xMaxOffset, originalOffset.x)),
MAX(-contentInset.top, MIN(yMaxOffset, originalOffset.y)));
}
}

Expand Down

0 comments on commit 2ea4bcd

Please sign in to comment.