Add backwards compatibility for React Native 0.13.x

This commit is contained in:
Scott Kyle 2015-11-13 11:15:44 -08:00
parent f3db7a5a56
commit 79540d7cba

View File

@ -15,7 +15,7 @@ extern "C" {
#endif
@interface NSObject ()
- (instancetype)initWithJSContext:(JSContext *)context NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithJSContext:(void *)context;
- (JSGlobalContextRef)ctx;
@end
@ -25,18 +25,22 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
return NULL;
}
id rctJSContext = contextIvar ? object_getIvar(executor, contextIvar) : nil;
id rctJSContext = object_getIvar(executor, contextIvar);
if (!rctJSContext && create) {
Class RCTJavaScriptContext = NSClassFromString(@"RCTJavaScriptContext");
if (RCTJavaScriptContext) {
NSMethodSignature *signature = [RCTJavaScriptContext instanceMethodSignatureForSelector:@selector(initWithJSContext:)];
assert(signature);
if (!strcmp([signature getArgumentTypeAtIndex:2], "@")) {
JSContext *context = [[JSContext alloc] init];
//JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:context];
object_setIvar(executor, contextIvar, rctJSContext);
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:(void *)context];
}
else {
NSLog(@"Failed to load RCTJavaScriptContext class");
JSGlobalContextRef ctx = JSGlobalContextCreate(NULL);
rctJSContext = [[RCTJavaScriptContext alloc] initWithJSContext:ctx];
}
object_setIvar(executor, contextIvar, rctJSContext);
}
return [rctJSContext ctx];