From 6052e97ba7ddaff7267b6319bc0b37382e21a919 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Tue, 11 Sep 2018 12:03:11 -0700 Subject: [PATCH] Added RCTJSINativeModule protocol to allow enabling JSI-bound nativemodule Summary: Instead of asking existing modules to implement `+allowJSIBinding`, introduce a temporary "empty" protocol so modules can just adopt it for migration purpose. Eventually this protocol may just go away. Modules need to adopt both `RCTBridgeModule` and `RCTJSINativeModule` for time being for backward compatibility. p.s. the entire system isn't enabled yet, this is just some of the pre-reqs for NativeModule improvements. Reviewed By: mmmulani Differential Revision: D9762913 fbshipit-source-id: 470f640f11a5991e5cfa9c48a1931da660ebfcd2 --- React/Base/RCTBridgeModule.h | 15 +++++++++------ React/CxxBridge/RCTCxxBridge.mm | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index b7726a061..26b2520f1 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -289,12 +289,6 @@ RCT_EXTERN void RCTRegisterModule(Class); \ */ + (BOOL)requiresMainQueueSetup; -/** - * Experimental. - * If YES, this module will be set up via JSI binding instead. - */ -+ (BOOL)allowJSIBinding; - /** * Injects methods into JS. Entries in this array are used in addition to any * methods defined using the macros above. This method is called only once, @@ -327,3 +321,12 @@ RCT_EXTERN void RCTRegisterModule(Class); \ - (void)partialBatchDidFlush; @end + +/** + * Experimental. + * A protocol to declare that a class supports JSI-bound NativeModule. + * This may be removed in the future. + */ +@protocol RCTJSINativeModule + +@end diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 22777864a..78b2d68d0 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -549,7 +549,7 @@ struct RCTInstanceCallback : public InstanceCallback { NSArray *moduleClassesCopy = [moduleClasses copy]; NSMutableArray *moduleDataByID = [NSMutableArray arrayWithCapacity:moduleClassesCopy.count]; for (Class moduleClass in moduleClassesCopy) { - if (RCTJSINativeModuleEnabled() && [moduleClass respondsToSelector:@selector(allowJSIBinding)] && [moduleClass allowJSIBinding]) { + if (RCTJSINativeModuleEnabled() && [moduleClass conformsToProtocol:@protocol(RCTJSINativeModule)]) { continue; } NSString *moduleName = RCTBridgeModuleNameForClass(moduleClass);