ScrollView: Smart `contentOffset` preserving
Summary: Previous `contentOffset` can be invalid for a new layout and overscroll the ScrollView, so the diff fixes that. Also documented here: https://github.com/facebook/react-native/issues/13566 Reviewed By: mmmulani Differential Revision: D5414442 fbshipit-source-id: 7de1b4a4571108a37d1795e80f165bca5aba5fef
This commit is contained in:
parent
301830dc2a
commit
1d22f8fb27
|
@ -325,10 +325,22 @@ static inline BOOL isRectInvalid(CGRect rect) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Preserving `contentOffset` between layout passes.
|
||||
// Preserving and revalidating `contentOffset`.
|
||||
CGPoint originalOffset = self.contentOffset;
|
||||
|
||||
[super setFrame:frame];
|
||||
self.contentOffset = originalOffset;
|
||||
|
||||
UIEdgeInsets contentInset = self.contentInset;
|
||||
CGSize contentSize = self.contentSize;
|
||||
CGSize fullContentSize = CGSizeMake(
|
||||
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 !TARGET_OS_TV
|
||||
|
|
Loading…
Reference in New Issue