Improved logging and dev menu

This commit is contained in:
Nick Lockwood
2015-04-19 12:55:46 -07:00
parent 2186691812
commit 0b21df4a34
11 changed files with 306 additions and 139 deletions

View File

@@ -19,10 +19,6 @@
NSUInteger _reloadRetries;
}
#ifndef DEBUG
static NSUInteger RCTReloadRetries = 0;
#endif
RCT_EXPORT_MODULE()
- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate
@@ -47,27 +43,32 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
return;
}
#ifdef DEBUG
#if DEBUG
[[RCTRedBox sharedInstance] showErrorMessage:message withStack:stack];
#else
if (RCTReloadRetries < _maxReloadAttempts) {
RCTReloadRetries++;
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil];
static NSUInteger reloadRetries = 0;
const NSUInteger maxMessageLength = 75;
if (reloadRetries < _maxReloadAttempts) {
reloadRetries++;
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification
object:nil];
} else {
NSError *error;
const NSUInteger MAX_SANITIZED_LENGTH = 75;
// Filter out numbers so the same base errors are mapped to the same categories independent of incorrect values.
NSString *pattern = @"[+-]?\\d+[,.]?\\d*";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
RCTAssert(error == nil, @"Bad regex pattern: %@", pattern);
NSString *sanitizedMessage = [regex stringByReplacingMatchesInString:message
options:0
range:NSMakeRange(0, message.length)
withTemplate:@"<num>"];
if (sanitizedMessage.length > MAX_SANITIZED_LENGTH) {
sanitizedMessage = [[sanitizedMessage substringToIndex:MAX_SANITIZED_LENGTH] stringByAppendingString:@"..."];
NSString *sanitizedMessage = [message stringByReplacingOccurrencesOfString:pattern withString:@"<num>" options:NSRegularExpressionSearch range:(NSRange){0, message.length}];
if (sanitizedMessage.length > maxMessageLength) {
sanitizedMessage = [[sanitizedMessage substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
}
NSMutableString *prettyStack = [@"\n" mutableCopy];
NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"];
for (NSDictionary *frame in stack) {
[prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]];
}
@@ -75,13 +76,21 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:sanitizedMessage];
[NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack];
}
#endif
}
RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message
stack:(NSArray *)stack)
{
#if DEBUG
[[RCTRedBox sharedInstance] updateErrorMessage:message withStack:stack];
#endif
}
@end

View File

@@ -999,7 +999,7 @@ RCT_EXPORT_METHOD(measureLayoutRelativeToParent:(NSNumber *)reactTag
* Only layouts for views that are within the rect passed in are returned. Invokes the error callback if the
* passed in parent view does not exist. Invokes the supplied callback with the array of computed layouts.
*/
RCT_EXPORT_METHOD(measureViewsInRect:(NSDictionary *)rect
RCT_EXPORT_METHOD(measureViewsInRect:(CGRect)rect
parentView:(NSNumber *)reactTag
errorCallback:(RCTResponseSenderBlock)errorCallback
callback:(RCTResponseSenderBlock)callback)
@@ -1011,7 +1011,7 @@ RCT_EXPORT_METHOD(measureViewsInRect:(NSDictionary *)rect
}
NSArray *childShadowViews = [shadowView reactSubviews];
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[childShadowViews count]];
CGRect layoutRect = [RCTConvert CGRect:rect];
[childShadowViews enumerateObjectsUsingBlock:^(RCTShadowView *childShadowView, NSUInteger idx, BOOL *stop) {
CGRect childLayout = [childShadowView measureLayoutRelativeToAncestor:shadowView];
@@ -1026,10 +1026,11 @@ RCT_EXPORT_METHOD(measureViewsInRect:(NSDictionary *)rect
CGFloat width = childLayout.size.width;
CGFloat height = childLayout.size.height;
if (leftOffset <= layoutRect.origin.x + layoutRect.size.width &&
leftOffset + width >= layoutRect.origin.x &&
topOffset <= layoutRect.origin.y + layoutRect.size.height &&
topOffset + height >= layoutRect.origin.y) {
if (leftOffset <= rect.origin.x + rect.size.width &&
leftOffset + width >= rect.origin.x &&
topOffset <= rect.origin.y + rect.size.height &&
topOffset + height >= rect.origin.y) {
// This view is within the layout rect
NSDictionary *result = @{@"index": @(idx),
@"left": @(leftOffset),