ScrollView: Use autoresizing masks for layouting actual UIScrollView

Summary:
Surprisingly enough, even if semantically the code remains identical, layouting via autoresizing masks applies changes to subviews a bit earlier than iOS calls `layoutSubviews`.
This allows us to avoid situations where we already explicitly set calculated by Yoga frames and want to scroll to some subview, but actual layout have not done yet and internal views has wrong frames.

Reviewed By: javache

Differential Revision: D5414440

fbshipit-source-id: d4152c9c68dc17f6827832dcb45e5ba86fb82831
This commit is contained in:
Valentin Shergin 2017-07-18 14:33:51 -07:00 committed by Facebook Github Bot
parent fa1d4e8d81
commit 301830dc2a
1 changed files with 4 additions and 4 deletions

View File

@ -325,7 +325,10 @@ static inline BOOL isRectInvalid(CGRect rect) {
return;
}
// Preserving `contentOffset` between layout passes.
CGPoint originalOffset = self.contentOffset;
[super setFrame:frame];
self.contentOffset = originalOffset;
}
#if !TARGET_OS_TV
@ -362,6 +365,7 @@ static inline BOOL isRectInvalid(CGRect rect) {
if ((self = [super initWithFrame:CGRectZero])) {
_eventDispatcher = eventDispatcher;
_scrollView = [[RCTCustomScrollView alloc] initWithFrame:CGRectZero];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_scrollView.delegate = self;
_scrollView.delaysContentTouches = NO;
_automaticallyAdjustContentInsets = YES;
@ -466,10 +470,6 @@ static inline void RCTApplyTranformationAccordingLayoutDirection(UIView *view, U
RCTAssert(self.subviews.count == 1, @"we should only have exactly one subview");
RCTAssert([self.subviews lastObject] == _scrollView, @"our only subview should be a scrollview");
CGPoint originalOffset = _scrollView.contentOffset;
_scrollView.frame = self.bounds;
_scrollView.contentOffset = originalOffset;
#if !TARGET_OS_TV
// Adjust the refresh control frame if the scrollview layout changes.
RCTRefreshControl *refreshControl = _scrollView.rctRefreshControl;