From 85f7569ce609ad5cdadb3836498a5c83c6c5187f Mon Sep 17 00:00:00 2001 From: Martin Kralik Date: Wed, 20 Apr 2016 11:19:37 -0700 Subject: [PATCH] fix incorrect layout for modal Summary:We had an issue where a rendered modal would not end up using the full screen size, but a size computed based on its initial content. Which is a small spinner in case of RelayContainer. So rarely we would end up with cut off view like this: {F60650629} This diff fixes this behavior by wrapping the content in another view. That makes the modal's wrapping VC's view resize just once when it's initially created. (Resize for the wrapping VC's view happened previously when the modal's content resized, which got us in the bad state.) Reviewed By: javache Differential Revision: D3202299 fb-gh-sync-id: 7c4dc1dbb27654292d07aef5916aa31df5cd4302 fbshipit-source-id: 7c4dc1dbb27654292d07aef5916aa31df5cd4302 --- React/Views/RCTModalHostView.m | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/React/Views/RCTModalHostView.m b/React/Views/RCTModalHostView.m index 75e50105c..b5908d0ab 100644 --- a/React/Views/RCTModalHostView.m +++ b/React/Views/RCTModalHostView.m @@ -22,6 +22,7 @@ BOOL _isPresented; RCTModalHostViewController *_modalViewController; RCTTouchHandler *_touchHandler; + UIView *_reactSubview; } RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) @@ -32,6 +33,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder) if ((self = [super initWithFrame:CGRectZero])) { _bridge = bridge; _modalViewController = [RCTModalHostViewController new]; + UIView *containerView = [UIView new]; + containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; + _modalViewController.view = containerView; _touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge]; _isPresented = NO; @@ -46,30 +50,33 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder) - (void)notifyForBoundsChange:(CGRect)newBounds { - if (_modalViewController.view && _isPresented) { - [_bridge.uiManager setFrame:newBounds forView:_modalViewController.view]; + if (_reactSubview && _isPresented) { + [_bridge.uiManager setFrame:newBounds forView:_reactSubview]; } } - (NSArray *)reactSubviews { - return _modalViewController.view ? @[_modalViewController.view] : @[]; + return _reactSubview ? @[_reactSubview] : @[]; } - (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex { - RCTAssert([_modalViewController.view reactTag] == nil, @"Modal view can only have one subview"); + RCTAssert(_reactSubview == nil, @"Modal view can only have one subview"); [subview addGestureRecognizer:_touchHandler]; subview.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; - _modalViewController.view = subview; + + [_modalViewController.view insertSubview:subview atIndex:0]; + _reactSubview = subview; } - (void)removeReactSubview:(UIView *)subview { - RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view"); + RCTAssert(subview == _reactSubview, @"Cannot remove view other than modal view"); [subview removeGestureRecognizer:_touchHandler]; - _modalViewController.view = nil; + [subview removeFromSuperview]; + _reactSubview = nil; } - (void)dismissModalViewController