@@ -70,7 +70,8 @@ - (void)loadExtraDataViewController;
70
70
71
71
@end
72
72
73
- @interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource>
73
+ @interface RCTRedBoxWindow : NSObject <UITableViewDelegate, UITableViewDataSource>
74
+ @property (nonatomic , strong ) UIViewController *rootViewController;
74
75
@property (nonatomic , weak ) id <RCTRedBoxWindowActionDelegate> actionDelegate;
75
76
@end
76
77
@@ -82,22 +83,17 @@ @implementation RCTRedBoxWindow
82
83
int _lastErrorCookie;
83
84
}
84
85
85
- - (instancetype )initWithFrame : (CGRect )frame customButtonTitles : (NSArray <NSString *>*)customButtonTitles customButtonHandlers : (NSArray <RCTRedBoxButtonPressHandler> *)customButtonHandlers
86
+ - (instancetype )initWithFrame : (CGRect )frame
87
+ customButtonTitles : (NSArray <NSString *>*)customButtonTitles
88
+ customButtonHandlers : (NSArray <RCTRedBoxButtonPressHandler> *)customButtonHandlers
86
89
{
87
- _lastErrorCookie = -1 ;
88
- if ((self = [super initWithFrame: frame])) {
89
- #if TARGET_OS_TV
90
- self.windowLevel = UIWindowLevelAlert + 1000 ;
91
- #else
92
- self.windowLevel = UIWindowLevelStatusBar - 1 ;
93
- #endif
94
- self.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 1 ];
95
- self.hidden = YES ;
90
+ if (self = [super init ]) {
91
+ _lastErrorCookie = -1 ;
96
92
97
- UIViewController *rootController = [UIViewController new ];
98
- self. rootViewController = rootController ;
99
- UIView * rootView = rootController. view ;
100
- rootView.backgroundColor = [UIColor clearColor ];
93
+ _rootViewController = [UIViewController new ];
94
+ UIView *rootView = _rootViewController. view ;
95
+ rootView. frame = frame ;
96
+ rootView.backgroundColor = [UIColor blackColor ];
101
97
102
98
const CGFloat buttonHeight = 60 ;
103
99
@@ -133,8 +129,8 @@ - (instancetype)initWithFrame:(CGRect)frame customButtonTitles:(NSArray<NSString
133
129
UIButton *copyButton = [self redBoxButton: copyText accessibilityIdentifier: @" redbox-copy" selector: @selector (copyStack ) block: nil ];
134
130
UIButton *extraButton = [self redBoxButton: extraText accessibilityIdentifier: @" redbox-extra" selector: @selector (showExtraDataViewController ) block: nil ];
135
131
136
- CGFloat buttonWidth = self. bounds .size .width / (4 + [customButtonTitles count ]);
137
- CGFloat bottomButtonHeight = self. bounds .size .height - buttonHeight - [self bottomSafeViewHeight ];
132
+ CGFloat buttonWidth = frame .size .width / (4 + [customButtonTitles count ]);
133
+ CGFloat bottomButtonHeight = frame .size .height - buttonHeight - [self bottomSafeViewHeight ];
138
134
dismissButton.frame = CGRectMake (0 , bottomButtonHeight, buttonWidth, buttonHeight);
139
135
reloadButton.frame = CGRectMake (buttonWidth, bottomButtonHeight, buttonWidth, buttonHeight);
140
136
copyButton.frame = CGRectMake (buttonWidth * 2 , bottomButtonHeight, buttonWidth, buttonHeight);
@@ -158,7 +154,7 @@ - (instancetype)initWithFrame:(CGRect)frame customButtonTitles:(NSArray<NSString
158
154
159
155
UIView *bottomSafeView = [UIView new ];
160
156
bottomSafeView.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 1 ];
161
- bottomSafeView.frame = CGRectMake (0 , self. bounds . size .height - [self bottomSafeViewHeight ], self. bounds .size .width , [self bottomSafeViewHeight ]);
157
+ bottomSafeView.frame = CGRectMake (0 , frame. size .height - [self bottomSafeViewHeight ], frame .size .width , [self bottomSafeViewHeight ]);
162
158
163
159
[rootView addSubview: bottomSafeView];
164
160
}
@@ -209,15 +205,18 @@ - (NSString *)stripAnsi:(NSString *)text
209
205
return [regex stringByReplacingMatchesInString: text options: 0 range: NSMakeRange (0 , [text length ]) withTemplate: @" " ];
210
206
}
211
207
212
- - (void )showErrorMessage : (NSString *)message withStack : (NSArray <RCTJSStackFrame *> *)stack isUpdate : (BOOL )isUpdate errorCookie : (int )errorCookie
208
+ - (void )showErrorMessage : (NSString *)message
209
+ withStack : (NSArray <RCTJSStackFrame *> *)stack
210
+ isUpdate : (BOOL )isUpdate
211
+ errorCookie : (int )errorCookie
213
212
{
214
213
// Remove ANSI color codes from the message
215
214
NSString *messageWithoutAnsi = [self stripAnsi: message];
216
215
217
216
// Show if this is a new message, or if we're updating the previous message
218
- BOOL isNew = self.hidden && !isUpdate;
217
+ BOOL isNew = ! self.rootViewController . isBeingPresented && !isUpdate;
219
218
BOOL isUpdateForSameMessage = !isNew && (
220
- ! self.hidden && isUpdate && (
219
+ self.rootViewController . isBeingPresented && isUpdate && (
221
220
(errorCookie == -1 && [_lastErrorMessage isEqualToString: messageWithoutAnsi]) ||
222
221
(errorCookie == _lastErrorCookie)
223
222
)
@@ -231,22 +230,20 @@ - (void)showErrorMessage:(NSString *)message withStack:(NSArray<RCTJSStackFrame
231
230
232
231
[_stackTraceTableView reloadData ];
233
232
234
- if (self.hidden ) {
233
+ if (! self.rootViewController . isBeingPresented ) {
235
234
[_stackTraceTableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0 ]
236
235
atScrollPosition: UITableViewScrollPositionTop
237
236
animated: NO ];
237
+ [RCTKeyWindow ().rootViewController presentViewController: self .rootViewController
238
+ animated: YES
239
+ completion: nil ];
238
240
}
239
-
240
- [self makeKeyAndVisible ];
241
- [self becomeFirstResponder ];
242
241
}
243
242
}
244
243
245
244
- (void )dismiss
246
245
{
247
- self.hidden = YES ;
248
- [self resignFirstResponder ];
249
- [RCTSharedApplication ().delegate.window makeKeyWindow ];
246
+ [self .rootViewController dismissViewControllerAnimated: YES completion: nil ];
250
247
}
251
248
252
249
- (void )reload
0 commit comments