mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 11:34:23 +00:00
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preserving `contentOffset` between layout passes.
|
// Preserving and revalidating `contentOffset`.
|
||||||
CGPoint originalOffset = self.contentOffset;
|
CGPoint originalOffset = self.contentOffset;
|
||||||
|
|
||||||
[super setFrame:frame];
|
[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
|
#if !TARGET_OS_TV
|
||||||
|
Loading…
x
Reference in New Issue
Block a user