Permalink
Browse files

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
  • Loading branch information...
shergin authored and facebook-github-bot committed Jul 18, 2017
1 parent fa1d4e8 commit 301830dc2a76fe30b795b5e12fedfcc620328e72
Showing with 4 additions and 4 deletions.
  1. +4 −4 React/Views/RCTScrollView.m
@@ -325,7 +325,10 @@ - (void)setFrame:(CGRect)frame
return;
}
// Preserving `contentOffset` between layout passes.
CGPoint originalOffset = self.contentOffset;
[super setFrame:frame];
self.contentOffset = originalOffset;
}
#if !TARGET_OS_TV
@@ -362,6 +365,7 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
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 @@ - (void)layoutSubviews
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;

0 comments on commit 301830d

Please sign in to comment.