mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
[ReactNative] orange box
Summary: @public There have been multiple instances of confusion about whether a redbox means the developer did something they shouldn't but things will keep working, or if something went horribly wrong and the app will crash in prod. This diff introduces an orange background color to the redbox for `console.error` and `RCTLogError` to indicate that something bad happened, but that the app will continue working. Test Plan: see orange error for geo permissions: {F22541375}
This commit is contained in:
parent
6358e163a5
commit
68bb3a7e71
@ -171,6 +171,9 @@ void _RCTLogFormat(
|
||||
|
||||
// Log to red box
|
||||
if (level >= RCTLOG_REDBOX_LEVEL) {
|
||||
if (level < RCTLOG_FATAL_LEVEL) {
|
||||
[[RCTRedBox sharedInstance] setNextBackgroundColor:[UIColor colorWithRed:0.9 green:0.4 blue:0.2 alpha:1]];
|
||||
}
|
||||
[[RCTRedBox sharedInstance] showErrorMessage:message];
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack;
|
||||
- (void)updateErrorMessage:(NSString *)message withStack:(NSArray *)stack;
|
||||
|
||||
- (void)setNextBackgroundColor:(UIColor *)color;
|
||||
|
||||
- (NSString *)currentErrorMessage;
|
||||
|
||||
- (void)dismiss;
|
||||
|
@ -29,14 +29,15 @@
|
||||
NSArray *_lastStackTrace;
|
||||
|
||||
UITableViewCell *_cachedMessageCell;
|
||||
UIColor *_redColor;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if ((self = [super initWithFrame:frame])) {
|
||||
|
||||
_redColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1];
|
||||
self.windowLevel = UIWindowLevelStatusBar + 5;
|
||||
self.backgroundColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1];
|
||||
self.backgroundColor = _redColor;
|
||||
self.hidden = YES;
|
||||
|
||||
UIViewController *rootController = [[UIViewController alloc] init];
|
||||
@ -132,6 +133,7 @@
|
||||
- (void)dismiss
|
||||
{
|
||||
self.hidden = YES;
|
||||
self.backgroundColor = _redColor;
|
||||
[self resignFirstResponder];
|
||||
[[[[UIApplication sharedApplication] delegate] window] makeKeyWindow];
|
||||
}
|
||||
@ -261,6 +263,7 @@
|
||||
@implementation RCTRedBox
|
||||
{
|
||||
RCTRedBoxWindow *_window;
|
||||
UIColor *_nextBackgroundColor;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
@ -273,6 +276,11 @@
|
||||
return _sharedInstance;
|
||||
}
|
||||
|
||||
- (void)setNextBackgroundColor:(UIColor *)color
|
||||
{
|
||||
_nextBackgroundColor = color;
|
||||
}
|
||||
|
||||
- (void)showErrorMessage:(NSString *)message
|
||||
{
|
||||
[self showErrorMessage:message withStack:nil showIfHidden:YES];
|
||||
@ -304,6 +312,10 @@
|
||||
_window = [[RCTRedBoxWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
}
|
||||
[_window showErrorMessage:message withStack:stack showIfHidden:shouldShow];
|
||||
if (_nextBackgroundColor) {
|
||||
_window.backgroundColor = _nextBackgroundColor;
|
||||
_nextBackgroundColor = nil;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -334,6 +346,7 @@
|
||||
- (void)updateErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
|
||||
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack showIfHidden:(BOOL)shouldShow {}
|
||||
- (NSString *)currentErrorMessage { return nil; }
|
||||
- (void)setNextBackgroundColor:(UIColor *)color {}
|
||||
- (void)dismiss {}
|
||||
|
||||
@end
|
||||
|
@ -44,7 +44,9 @@ RCT_EXPORT_METHOD(reportSoftException:(NSString *)message
|
||||
[_delegate handleSoftJSExceptionWithMessage:message stack:stack];
|
||||
return;
|
||||
}
|
||||
// JS already logs the error via console.
|
||||
RCTRedBox *box = [RCTRedBox sharedInstance];
|
||||
[box setNextBackgroundColor:[UIColor colorWithRed:0.9 green:0.4 blue:0.2 alpha:1]];
|
||||
[box showErrorMessage:message withStack:stack];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
|
||||
|
Loading…
x
Reference in New Issue
Block a user