Merge pull request #136 from realm/al-version

Support RectNative version 0.14
This commit is contained in:
Ari Lazier 2015-11-13 11:30:22 -08:00
commit 8e9a14e1c0
3 changed files with 17 additions and 11 deletions

View File

@ -14,8 +14,8 @@ extern "C" {
#import <GCDWebServers/GCDWebServers.h> #import <GCDWebServers/GCDWebServers.h>
#endif #endif
@interface NSObject (RCTJavaScriptContext) @interface NSObject ()
- (instancetype)initWithJSContext:(JSGlobalContextRef)context; - (instancetype)initWithJSContext:(void *)context;
- (JSGlobalContextRef)ctx; - (JSGlobalContextRef)ctx;
@end @end
@ -25,19 +25,25 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
return NULL; return NULL;
} }
id rctJSContext = contextIvar ? object_getIvar(executor, contextIvar) : nil; id rctJSContext = object_getIvar(executor, contextIvar);
if (!rctJSContext && create) { if (!rctJSContext && create) {
Class RCTJavaScriptContext = NSClassFromString(@"RCTJavaScriptContext"); Class RCTJavaScriptContext = NSClassFromString(@"RCTJavaScriptContext");
if (RCTJavaScriptContext) { NSMethodSignature *signature = [RCTJavaScriptContext instanceMethodSignatureForSelector:@selector(initWithJSContext:)];
JSGlobalContextRef ctx = JSGlobalContextCreate(NULL); assert(signature);
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:ctx];
object_setIvar(executor, contextIvar, rctJSContext); // React Native 0.14+ expects a JSContext here, but we also support 0.13.x, which takes a JSGlobalContextRef.
if (!strcmp([signature getArgumentTypeAtIndex:2], "@")) {
JSContext *context = [[JSContext alloc] init];
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:(void *)context];
} }
else { else {
NSLog(@"Failed to load RCTJavaScriptContext class"); JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:ctx];
} }
object_setIvar(executor, contextIvar, rctJSContext);
} }
return [rctJSContext ctx]; return [rctJSContext ctx];
} }
} }

View File

@ -6,7 +6,7 @@
"start": "node_modules/react-native/packager/packager.sh" "start": "node_modules/react-native/packager/packager.sh"
}, },
"dependencies": { "dependencies": {
"react-native": "0.13.2", "react-native": "0.14.2",
"realm": "file:../../lib" "realm": "file:../../lib"
} }
} }

View File

@ -6,7 +6,7 @@
"start": "node_modules/react-native/packager/packager.sh" "start": "node_modules/react-native/packager/packager.sh"
}, },
"dependencies": { "dependencies": {
"react-native": "0.13.2", "react-native": "0.14.2",
"realm": "file:../../lib", "realm": "file:../../lib",
"realm-tests": "file:.." "realm-tests": "file:.."
} }