@@ -134,7 +134,7 @@ - (instancetype)initWithFrame:(CGRect)frame
134
134
135
135
CGFloat buttonWidth = self.bounds .size .width / 4 ;
136
136
CGFloat bottomButtonHeight = self.bounds .size .height - buttonHeight - [self bottomSafeViewHeight ];
137
-
137
+
138
138
dismissButton.frame = CGRectMake (0 , bottomButtonHeight, buttonWidth, buttonHeight);
139
139
reloadButton.frame = CGRectMake (buttonWidth, bottomButtonHeight, buttonWidth, buttonHeight);
140
140
copyButton.frame = CGRectMake (buttonWidth * 2 , bottomButtonHeight, buttonWidth, buttonHeight);
@@ -148,11 +148,11 @@ - (instancetype)initWithFrame:(CGRect)frame
148
148
[rootView addSubview: copyButton];
149
149
[rootView addSubview: extraButton];
150
150
[rootView addSubview: topBorder];
151
-
151
+
152
152
UIView *bottomSafeView = [UIView new ];
153
153
bottomSafeView.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 1 ];
154
154
bottomSafeView.frame = CGRectMake (0 , self.bounds .size .height - [self bottomSafeViewHeight ], self.bounds .size .width , [self bottomSafeViewHeight ]);
155
-
155
+
156
156
[rootView addSubview: bottomSafeView];
157
157
}
158
158
return self;
@@ -176,14 +176,24 @@ - (void)dealloc
176
176
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
177
177
}
178
178
179
+ - (NSString *)stripAnsi : (NSString *)text
180
+ {
181
+ NSError *error = nil ;
182
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: @" \\ x1b\\ [[0-9;]*m" options: NSRegularExpressionCaseInsensitive error: &error];
183
+ return [regex stringByReplacingMatchesInString: text options: 0 range: NSMakeRange (0 , [text length ]) withTemplate: @" " ];
184
+ }
185
+
179
186
- (void )showErrorMessage : (NSString *)message withStack : (NSArray <RCTJSStackFrame *> *)stack isUpdate : (BOOL )isUpdate
180
187
{
188
+ // Remove ANSI color codes from the message
189
+ NSString *messageWithoutAnsi = [self stripAnsi: message];
190
+
181
191
// Show if this is a new message, or if we're updating the previous message
182
- if ((self.hidden && !isUpdate) || (!self.hidden && isUpdate && [_lastErrorMessage isEqualToString: message ])) {
192
+ if ((self.hidden && !isUpdate) || (!self.hidden && isUpdate && [_lastErrorMessage isEqualToString: messageWithoutAnsi ])) {
183
193
_lastStackTrace = stack;
184
194
// message is displayed using UILabel, which is unable to render text of
185
195
// unlimited length, so we truncate it
186
- _lastErrorMessage = [message substringToIndex: MIN ((NSUInteger )10000 , message .length)];
196
+ _lastErrorMessage = [messageWithoutAnsi substringToIndex: MIN ((NSUInteger )10000 , messageWithoutAnsi .length)];
187
197
188
198
[_stackTraceTableView reloadData ];
189
199
0 commit comments