@@ -29,7 +29,8 @@ - (void)loadExtraDataViewController;
29
29
@end
30
30
31
31
#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
32
- @interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource>
32
+ @interface RCTRedBoxWindow : NSObject <UITableViewDelegate, UITableViewDataSource>
33
+ @property (nonatomic , strong ) UIViewController *rootViewController;
33
34
@property (nonatomic , weak ) id <RCTRedBoxWindowActionDelegate> actionDelegate;
34
35
@end
35
36
@@ -42,19 +43,11 @@ @implementation RCTRedBoxWindow
42
43
43
44
- (instancetype )initWithFrame : (CGRect)frame
44
45
{
45
- if ((self = [super initWithFrame: frame])) {
46
- #if TARGET_OS_TV
47
- self.windowLevel = UIWindowLevelAlert + 1000 ;
48
- #else
49
- self.windowLevel = UIWindowLevelStatusBar - 1 ;
50
- #endif
51
- self.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 1 ];
52
- self.hidden = YES ;
53
-
54
- UIViewController *rootController = [UIViewController new ];
55
- self.rootViewController = rootController;
56
- UIView *rootView = rootController.view ;
57
- rootView.backgroundColor = [UIColor clearColor ];
46
+ if ((self = [super init ])) {
47
+ _rootViewController = [UIViewController new ];
48
+ UIView *rootView = _rootViewController.view ;
49
+ rootView.frame = frame;
50
+ rootView.backgroundColor = [UIColor blackColor ];
58
51
59
52
const CGFloat buttonHeight = 60 ;
60
53
@@ -133,8 +126,8 @@ - (instancetype)initWithFrame:(CGRect)frame
133
126
[extraButton setTitleColor: [UIColor colorWithWhite: 1 alpha: 0.5 ] forState: UIControlStateHighlighted];
134
127
[extraButton addTarget: self action: @selector (showExtraDataViewController ) forControlEvents: UIControlEventTouchUpInside];
135
128
136
- CGFloat buttonWidth = self. bounds .size .width / 4 ;
137
- CGFloat bottomButtonHeight = self. bounds .size .height - buttonHeight - [self bottomSafeViewHeight ];
129
+ CGFloat buttonWidth = frame .size .width / 4 ;
130
+ CGFloat bottomButtonHeight = frame .size .height - buttonHeight - [self bottomSafeViewHeight ];
138
131
139
132
dismissButton.frame = CGRectMake (0 , bottomButtonHeight, buttonWidth, buttonHeight);
140
133
reloadButton.frame = CGRectMake (buttonWidth, bottomButtonHeight, buttonWidth, buttonHeight);
@@ -152,7 +145,7 @@ - (instancetype)initWithFrame:(CGRect)frame
152
145
153
146
UIView *bottomSafeView = [UIView new ];
154
147
bottomSafeView.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 1 ];
155
- bottomSafeView.frame = CGRectMake (0 , self. bounds . size .height - [self bottomSafeViewHeight ], self. bounds .size .width , [self bottomSafeViewHeight ]);
148
+ bottomSafeView.frame = CGRectMake (0 , frame. size .height - [self bottomSafeViewHeight ], frame .size .width , [self bottomSafeViewHeight ]);
156
149
157
150
[rootView addSubview: bottomSafeView];
158
151
}
@@ -190,30 +183,29 @@ - (void)showErrorMessage:(NSString *)message withStack:(NSArray<RCTJSStackFrame
190
183
NSString *messageWithoutAnsi = [self stripAnsi: message];
191
184
192
185
// Show if this is a new message, or if we're updating the previous message
193
- if ((self.hidden && !isUpdate) || (!self.hidden && isUpdate && [_lastErrorMessage isEqualToString: messageWithoutAnsi])) {
186
+ BOOL hidden = !self.rootViewController .isBeingPresented ;
187
+ if ((hidden && !isUpdate) || (!hidden && isUpdate && [_lastErrorMessage isEqualToString: messageWithoutAnsi])) {
194
188
_lastStackTrace = stack;
195
189
// message is displayed using UILabel, which is unable to render text of
196
190
// unlimited length, so we truncate it
197
191
_lastErrorMessage = [messageWithoutAnsi substringToIndex: MIN ((NSUInteger )10000 , messageWithoutAnsi.length)];
198
192
199
193
[_stackTraceTableView reloadData ];
200
194
201
- if (self. hidden ) {
195
+ if (hidden) {
202
196
[_stackTraceTableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0 ]
203
197
atScrollPosition: UITableViewScrollPositionTop
204
198
animated: NO ];
199
+ [RCTKeyWindow ().rootViewController presentViewController: self .rootViewController
200
+ animated: YES
201
+ completion: nil ];
205
202
}
206
-
207
- [self makeKeyAndVisible ];
208
- [self becomeFirstResponder ];
209
203
}
210
204
}
211
205
212
206
- (void )dismiss
213
207
{
214
- self.hidden = YES ;
215
- [self resignFirstResponder ];
216
- [RCTSharedApplication ().delegate.window makeKeyWindow ];
208
+ [self .rootViewController dismissViewControllerAnimated: YES completion: nil ];
217
209
}
218
210
219
211
- (void )reload
@@ -554,13 +546,13 @@ - (void)showErrorMessage:(NSString *)message withStack:(NSArray<RCTJSStackFrame
554
546
if (!_visible) {
555
547
_visible = YES ;
556
548
[_window center ];
557
- if (!RCTRunningInTestEnvironment ()) {
558
- [NSApp runModalForWindow: _window];
559
- }
560
- else {
561
- [NSApp activateIgnoringOtherApps: YES ];
562
- [[NSApp mainWindow ] makeKeyAndOrderFront: _window];
563
- }
549
+ if (!RCTRunningInTestEnvironment ()) {
550
+ [NSApp runModalForWindow: _window];
551
+ }
552
+ else {
553
+ [NSApp activateIgnoringOtherApps: YES ];
554
+ [[NSApp mainWindow ] makeKeyAndOrderFront: _window];
555
+ }
564
556
}
565
557
}
566
558
}
@@ -881,6 +873,7 @@ - (void)loadExtraDataViewController {
881
873
#else // ]TODO(macOS ISS#2323203)
882
874
dispatch_async (dispatch_get_main_queue (), ^{
883
875
[self ->_window dismiss ];
876
+ self->_window = nil ; // TODO(OSS Candidate ISS#2710739): release _window now to ensure its UIKit ivars are dealloc'd on the main thread as the RCTRedBox can be dealloc'd on a background thread.
884
877
});
885
878
#endif // TODO(macOS ISS#2323203)
886
879
}
0 commit comments