From 1148ac54173eee61b4c6db667437954396096b24 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 2 Sep 2015 20:01:15 -0700 Subject: [PATCH] support react-native version 0.10.0 --- ReactNative/RealmReactModule.h | 1 - ReactNative/RealmReactModule.m | 17 +++++++++++++---- examples/ReactExample/package.json | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ReactNative/RealmReactModule.h b/ReactNative/RealmReactModule.h index 30318fdf..e106123c 100644 --- a/ReactNative/RealmReactModule.h +++ b/ReactNative/RealmReactModule.h @@ -23,5 +23,4 @@ @protocol RCTBridgeModule; @interface Realm : NSObject - @end diff --git a/ReactNative/RealmReactModule.m b/ReactNative/RealmReactModule.m index 723ac55f..231b20ae 100644 --- a/ReactNative/RealmReactModule.m +++ b/ReactNative/RealmReactModule.m @@ -24,9 +24,10 @@ @import RealmJS; @import JavaScriptCore; -@protocol RCTJavaScriptContext +@interface RCTJavaScriptContext : NSObject @property (nonatomic, assign, readonly) JSGlobalContextRef ctx; - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block; +- (instancetype)initWithJSContext:(JSGlobalContextRef)context; @end RCT_EXTERN id RCTGetLatestExecutor(void); @@ -41,16 +42,24 @@ RCT_EXPORT_MODULE() _bridge = bridge; id contextExecutor = RCTGetLatestExecutor(); - [contextExecutor executeBlockOnJavaScriptQueue:^{ Ivar ivar = class_getInstanceVariable([contextExecutor class], "_context"); - id rctJSContext = object_getIvar(contextExecutor, ivar); - JSContextRef ctx = rctJSContext.ctx; + RCTJavaScriptContext *rctJSContext = object_getIvar(contextExecutor, ivar); + JSGlobalContextRef ctx; + if (rctJSContext) { + ctx = rctJSContext.ctx; + } + else { + ctx = JSGlobalContextCreate(NULL); + object_setIvar(contextExecutor, ivar, [[RCTJavaScriptContext alloc] initWithJSContext:ctx]); + } [RealmJS initializeContext:ctx]; + RCTLogInfo(@"Realm initialized"); }]; } + @end diff --git a/examples/ReactExample/package.json b/examples/ReactExample/package.json index 39b2f649..c9851577 100644 --- a/examples/ReactExample/package.json +++ b/examples/ReactExample/package.json @@ -6,6 +6,6 @@ "start": "node_modules/react-native/packager/packager.sh" }, "dependencies": { - "react-native": "^0.8.0" + "react-native": "0.10.0" } }