Skip to content

Commit 64be883

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
Fix content offset validation
Summary: Content offset was broken because on initial render contentSize is {0,0} so any positive offset is lost. Also inset top/bottom and left/right were inversed �, this led to bad initial scrolling offset when using contentInset. This fixes it by making sure contentSize is actually measured (not {0,0}. I guess it's possible that the content is ACTUALLY {0,0} but in that case I don't think it really matters). **Test plan** Tested that a scrollview has proper scroll position when specifying contentOffset. Also tested that it works well with contentInset. ```js <ScrollView contentOffset={{y: 100}}> <View style={{height: 1000}} /> </ScrollView> ``` Closes #15670 Differential Revision: D5771221 Pulled By: shergin fbshipit-source-id: 455ed8fd5a4ad1ec61780b573d1a8ef1d77dd124
1 parent ed31f7a commit 64be883

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

React/Views/RCTScrollView.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,17 @@ - (void)setFrame:(CGRect)frame
315315

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

326331
#if !TARGET_OS_TV

0 commit comments

Comments
 (0)