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
This commit is contained in:
Martin Kralik
2016-04-20 11:19:37 -07:00
committed by Facebook Github Bot 0
parent eff673572e
commit 85f7569ce6

View File

@@ -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<UIView *> *)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