[ReactNative] Add RCTAssertThread and restrict -[UIManager addUIBlock:] to _shadowQueue

Summary:
@public

Add `RCTAssertThread` to `RCTAssert.h` for convenience when checking the current/queue,
it accepts either a `NSString *`, `NSThread *` or `dispatch_queue_t` as the object to be checked

Also add a check to `-[RCTUIManager addUIBlock:]` - There was a discussion on github (https://github.com/facebook/react-native/issues/1365)
due to the weird behavior caused by calling it from a different thread/queue (it might be added after `batchDidComplete` has been called
and will just be dispatched on the next call from JS to objc)

Test Plan:
Change `-[RCTAnimationExperimentalManager methodQueue]` to return `dispatch_get_main_queue()` and run the 2048 example,
it should dispatch with a helpful message (screenshot on the comments)
This commit is contained in:
Tadeu Zagallo
2015-05-25 05:19:53 -07:00
parent c91e2eb567
commit 9062bda79b
6 changed files with 55 additions and 29 deletions

View File

@@ -53,7 +53,7 @@ RCTLogFunction RCTDefaultLogFunction = ^(
)
{
NSString *log = RCTFormatLog(
[NSDate date], [NSThread currentThread], level, fileName, lineNumber, message
[NSDate date], level, fileName, lineNumber, message
);
fprintf(stderr, "%s\n", log.UTF8String);
fflush(stderr);
@@ -99,25 +99,8 @@ void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix)
[prefixStack removeLastObject];
}
NSString *RCTThreadName(NSThread *thread)
{
NSString *threadName = [thread isMainThread] ? @"main" : thread.name;
if (threadName.length == 0) {
#if DEBUG // This is DEBUG not RCT_DEBUG because it *really* must not ship in RC
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
threadName = @(dispatch_queue_get_label(dispatch_get_current_queue()));
#pragma clang diagnostic pop
#else
threadName = [NSString stringWithFormat:@"%p", thread];
#endif
}
return threadName;
}
NSString *RCTFormatLog(
NSDate *timestamp,
NSThread *thread,
RCTLogLevel level,
NSString *fileName,
NSNumber *lineNumber,
@@ -137,9 +120,9 @@ NSString *RCTFormatLog(
if (level) {
[log appendFormat:@"[%s]", RCTLogLevels[level - 1]];
}
if (thread) {
[log appendFormat:@"[tid:%@]", RCTThreadName(thread)];
}
[log appendFormat:@"[tid:%@]", RCTCurrentThreadName()];
if (fileName) {
fileName = [fileName lastPathComponent];
if (lineNumber) {