From 79540d7cbaae23454d876bcb2c219316d1ecaa24 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Fri, 13 Nov 2015 11:15:44 -0800 Subject: [PATCH] Add backwards compatibility for React Native 0.13.x --- ReactNative/RealmReact.mm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ReactNative/RealmReact.mm b/ReactNative/RealmReact.mm index e68a7bb0..66135a01 100644 --- a/ReactNative/RealmReact.mm +++ b/ReactNative/RealmReact.mm @@ -15,7 +15,7 @@ extern "C" { #endif @interface NSObject () -- (instancetype)initWithJSContext:(JSContext *)context NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithJSContext:(void *)context; - (JSGlobalContextRef)ctx; @end @@ -25,20 +25,24 @@ 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]; } }