Skip to content

Commit 85f7569

Browse files
majakFacebook Github Bot 0
authored andcommitted
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
1 parent eff6735 commit 85f7569

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

React/Views/RCTModalHostView.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ @implementation RCTModalHostView
2222
BOOL _isPresented;
2323
RCTModalHostViewController *_modalViewController;
2424
RCTTouchHandler *_touchHandler;
25+
UIView *_reactSubview;
2526
}
2627

2728
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
@@ -32,6 +33,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
3233
if ((self = [super initWithFrame:CGRectZero])) {
3334
_bridge = bridge;
3435
_modalViewController = [RCTModalHostViewController new];
36+
UIView *containerView = [UIView new];
37+
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
38+
_modalViewController.view = containerView;
3539
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
3640
_isPresented = NO;
3741

@@ -46,30 +50,33 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
4650

4751
- (void)notifyForBoundsChange:(CGRect)newBounds
4852
{
49-
if (_modalViewController.view && _isPresented) {
50-
[_bridge.uiManager setFrame:newBounds forView:_modalViewController.view];
53+
if (_reactSubview && _isPresented) {
54+
[_bridge.uiManager setFrame:newBounds forView:_reactSubview];
5155
}
5256
}
5357

5458
- (NSArray<UIView *> *)reactSubviews
5559
{
56-
return _modalViewController.view ? @[_modalViewController.view] : @[];
60+
return _reactSubview ? @[_reactSubview] : @[];
5761
}
5862

5963
- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex
6064
{
61-
RCTAssert([_modalViewController.view reactTag] == nil, @"Modal view can only have one subview");
65+
RCTAssert(_reactSubview == nil, @"Modal view can only have one subview");
6266
[subview addGestureRecognizer:_touchHandler];
6367
subview.autoresizingMask = UIViewAutoresizingFlexibleHeight |
6468
UIViewAutoresizingFlexibleWidth;
65-
_modalViewController.view = subview;
69+
70+
[_modalViewController.view insertSubview:subview atIndex:0];
71+
_reactSubview = subview;
6672
}
6773

6874
- (void)removeReactSubview:(UIView *)subview
6975
{
70-
RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view");
76+
RCTAssert(subview == _reactSubview, @"Cannot remove view other than modal view");
7177
[subview removeGestureRecognizer:_touchHandler];
72-
_modalViewController.view = nil;
78+
[subview removeFromSuperview];
79+
_reactSubview = nil;
7380
}
7481

7582
- (void)dismissModalViewController

0 commit comments

Comments
 (0)