|
16 | 16 | #import "RCTUIManager.h" |
17 | 17 | #import "UIView+React.h" |
18 | 18 |
|
| 19 | +#import <UIKit/UIKit.h> |
| 20 | + |
19 | 21 | @implementation RCTModalHostView |
20 | 22 | { |
21 | 23 | __weak RCTBridge *_bridge; |
22 | 24 | BOOL _isPresented; |
23 | 25 | RCTModalHostViewController *_modalViewController; |
24 | 26 | RCTTouchHandler *_touchHandler; |
25 | 27 | UIView *_reactSubview; |
| 28 | + UIInterfaceOrientation _lastKnownOrientation; |
26 | 29 | } |
27 | 30 |
|
28 | 31 | RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) |
@@ -52,7 +55,28 @@ - (void)notifyForBoundsChange:(CGRect)newBounds |
52 | 55 | { |
53 | 56 | if (_reactSubview && _isPresented) { |
54 | 57 | [_bridge.uiManager setFrame:newBounds forView:_reactSubview]; |
| 58 | + [self notifyForOrientationChange]; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +- (void)notifyForOrientationChange |
| 63 | +{ |
| 64 | + if (!_onOrientationChange) { |
| 65 | + return; |
55 | 66 | } |
| 67 | + |
| 68 | + UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation]; |
| 69 | + if (currentOrientation == _lastKnownOrientation) { |
| 70 | + return; |
| 71 | + } |
| 72 | + _lastKnownOrientation = currentOrientation; |
| 73 | + |
| 74 | + BOOL isPortrait = currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown; |
| 75 | + NSDictionary *eventPayload = |
| 76 | + @{ |
| 77 | + @"orientation": isPortrait ? @"portrait" : @"landscape", |
| 78 | + }; |
| 79 | + _onOrientationChange(eventPayload); |
56 | 80 | } |
57 | 81 |
|
58 | 82 | - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex |
@@ -95,6 +119,7 @@ - (void)didMoveToWindow |
95 | 119 | if (!_isPresented && self.window) { |
96 | 120 | RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller"); |
97 | 121 |
|
| 122 | + _modalViewController.supportedInterfaceOrientations = [self supportedOrientationsMask]; |
98 | 123 | if ([self.animationType isEqualToString:@"fade"]) { |
99 | 124 | _modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; |
100 | 125 | } else if ([self.animationType isEqualToString:@"slide"]) { |
@@ -136,4 +161,31 @@ - (void)setTransparent:(BOOL)transparent |
136 | 161 | _modalViewController.modalPresentationStyle = transparent ? UIModalPresentationCustom : UIModalPresentationFullScreen; |
137 | 162 | } |
138 | 163 |
|
| 164 | +- (UIInterfaceOrientationMask)supportedOrientationsMask |
| 165 | +{ |
| 166 | + if (_supportedOrientations.count == 0) { |
| 167 | + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { |
| 168 | + return UIInterfaceOrientationMaskAll; |
| 169 | + } else { |
| 170 | + return UIInterfaceOrientationMaskPortrait; |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + UIInterfaceOrientationMask supportedOrientations = 0; |
| 175 | + for (NSString *orientation in _supportedOrientations) { |
| 176 | + if ([orientation isEqualToString:@"portrait"]) { |
| 177 | + supportedOrientations |= UIInterfaceOrientationMaskPortrait; |
| 178 | + } else if ([orientation isEqualToString:@"portrait-upside-down"]) { |
| 179 | + supportedOrientations |= UIInterfaceOrientationMaskPortraitUpsideDown; |
| 180 | + } else if ([orientation isEqualToString:@"landscape"]) { |
| 181 | + supportedOrientations |= UIInterfaceOrientationMaskLandscape; |
| 182 | + } else if ([orientation isEqualToString:@"landscape-left"]) { |
| 183 | + supportedOrientations |= UIInterfaceOrientationMaskLandscapeLeft; |
| 184 | + } else if ([orientation isEqualToString:@"landscape-right"]) { |
| 185 | + supportedOrientations |= UIInterfaceOrientationMaskLandscapeRight; |
| 186 | + } |
| 187 | + } |
| 188 | + return supportedOrientations; |
| 189 | +} |
| 190 | + |
139 | 191 | @end |
0 commit comments