Skip to content

Commit

Permalink
[iOS] Use bridge dispatchBlock, thank @javache, refs #1121
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Jul 6, 2017
1 parent 7a9d469 commit d2bef43
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions react-native/ios/RealmReact/RealmReact.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import "RealmReact.h"
#import "RealmAnalytics.h"
#import "RCTBridge.h"
#import "RCTBridge+Private.h"
#import "RCTJavaScriptExecutor.h"

#import "jsc_init.h"
Expand Down Expand Up @@ -309,7 +309,7 @@ - (void)setBridge:(RCTBridge *)bridge {
__weak __typeof__(self) weakSelf = self;
__weak __typeof__(bridge) weakBridge = bridge;

dispatch_block_t bridgeInitializer = ^{
[bridge dispatchBlock:^{
__typeof__(self) self = weakSelf;
__typeof__(bridge) bridge = weakBridge;
if (!self || !bridge) {
Expand All @@ -319,22 +319,13 @@ - (void)setBridge:(RCTBridge *)bridge {
_initializeOnJSThread(^{
return [bridge jsContextRef];
});
};

Class RCTCxxBridgeClass = NSClassFromString(@"RCTCxxBridge");
if ([RCTCxxBridgeClass instancesRespondToSelector:@selector(ensureOnJavaScriptThread:)]) {
[bridge ensureOnJavaScriptThread:bridgeInitializer];
} else {
[bridge executeBlockOnJavaScriptThread:bridgeInitializer];
}

return;
} queue:RCTJSThread];
} else { // React Native 0.44 and older
id<RCTJavaScriptExecutor> executor = [bridge valueForKey:@"javaScriptExecutor"];
__weak __typeof__(self) weakSelf = self;
__weak __typeof__(executor) weakExecutor = executor;

[executor executeBlockOnJavaScriptQueue:^{
[bridge dispatchBlock:^{
__typeof__(self) self = weakSelf;
__typeof__(executor) executor = weakExecutor;
if (!self || !executor) {
Expand All @@ -344,7 +335,7 @@ - (void)setBridge:(RCTBridge *)bridge {
_initializeOnJSThread(^ {
return RealmReactGetJSGlobalContextForExecutor(executor, true);
});
}];
} queue:RCTJSThread];
}
}

Expand Down

0 comments on commit d2bef43

Please sign in to comment.