mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user