Skip to content

Commit

Permalink
support react-native version 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alazier committed Sep 3, 2015
1 parent 7ac7ab3 commit 1148ac5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion ReactNative/RealmReactModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
@protocol RCTBridgeModule;

@interface Realm : NSObject <RCTBridgeModule>

@end
17 changes: 13 additions & 4 deletions ReactNative/RealmReactModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
@import RealmJS;
@import JavaScriptCore;

@protocol RCTJavaScriptContext
@interface RCTJavaScriptContext : NSObject <RCTInvalidating>
@property (nonatomic, assign, readonly) JSGlobalContextRef ctx;
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block;
- (instancetype)initWithJSContext:(JSGlobalContextRef)context;
@end

RCT_EXTERN id<RCTJavaScriptExecutor> RCTGetLatestExecutor(void);
Expand All @@ -41,16 +42,24 @@ -(void)setBridge:(RCTBridge *)bridge {
_bridge = bridge;

id contextExecutor = RCTGetLatestExecutor();

[contextExecutor executeBlockOnJavaScriptQueue:^{
Ivar ivar = class_getInstanceVariable([contextExecutor class], "_context");
id<RCTJavaScriptContext> 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

2 changes: 1 addition & 1 deletion examples/ReactExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"start": "node_modules/react-native/packager/packager.sh"
},
"dependencies": {
"react-native": "^0.8.0"
"react-native": "0.10.0"
}
}

0 comments on commit 1148ac5

Please sign in to comment.