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