mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fixed ScrollView adjust inset behavior (#23555)
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: https://github.com/facebook/react-native/pull/23555 Differential Revision: D14161593 Pulled By: cpojer fbshipit-source-id: 01434e55106ffde7f8e39f66dd5b0f02df9b38b1
This commit is contained in:
committed by
Facebook Github Bot
parent
536045276c
commit
2ea4bcd001
@@ -323,11 +323,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user