[ReactNative] Add completionBlock to -[RCTBridge enqueueJSCall:args:]

Summary:
@public

Allow to pass an optional completion block to the bridge JS calls.

The block will be called from the JS thread, after the javascript has finished
running and the returned calls have been processed/dispatched to the native modules.

Test Plan: Added `testCallbackIsCalledOnTheRightTime` to `RKBatchedBridgeTests`
This commit is contained in:
Tadeu Zagallo
2015-05-28 08:29:19 -07:00
parent ebae151f24
commit 3b24f52a20
4 changed files with 105 additions and 15 deletions

View File

@@ -273,3 +273,14 @@ BOOL RCTImageHasAlpha(CGImageRef image)
return YES;
}
}
BOOL _RCTRunLoopRunWhile(BOOL (^block)(void), NSTimeInterval timeout)
{
NSDate *timeoutDate = [[NSDate date] dateByAddingTimeInterval:timeout];
while (block() && [timeoutDate timeIntervalSinceNow] > 0) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
}
return !block();
}