[iOS] Support RN 0.46+, #1121 (#1122)

* [iOS] Support RN 0.46+, #1121

* [iOS] Use bridge dispatchBlock, thank @javache, refs #1121

* [iOS] Drop unneeded expose of private methods for RCTBridge, refs #1121
This commit is contained in:
Dmitry Patsura 2017-07-06 23:13:03 +09:00 committed by Yavor Georgiev
parent 80253cdbac
commit 13cd978a87

View File

@ -18,7 +18,7 @@
#import "RealmReact.h"
#import "RealmAnalytics.h"
#import "RCTBridge.h"
#import "RCTBridge+Private.h"
#import "RCTJavaScriptExecutor.h"
#import "jsc_init.h"
@ -52,7 +52,6 @@ using namespace realm::rpc;
// the part of the RCTCxxBridge private class we care about
@interface RCTBridge (RCTCxxBridge)
- (JSGlobalContextRef)jsContextRef;
- (void)executeBlockOnJavaScriptThread:(dispatch_block_t)block;
@end
extern "C" JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool create) {
@ -305,7 +304,8 @@ void _initializeOnJSThread(JSContextRefExtractor jsContextExtractor) {
__weak __typeof__(self) weakSelf = self;
__weak __typeof__(bridge) weakBridge = bridge;
[bridge executeBlockOnJavaScriptThread:^{
[bridge dispatchBlock:^{
__typeof__(self) self = weakSelf;
__typeof__(bridge) bridge = weakBridge;
if (!self || !bridge) {
@ -315,14 +315,13 @@ void _initializeOnJSThread(JSContextRefExtractor jsContextExtractor) {
_initializeOnJSThread(^{
return [bridge jsContextRef];
});
}];
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) {
@ -332,7 +331,7 @@ void _initializeOnJSThread(JSContextRefExtractor jsContextExtractor) {
_initializeOnJSThread(^ {
return RealmReactGetJSGlobalContextForExecutor(executor, true);
});
}];
} queue:RCTJSThread];
}
}