1 // Copyright 2015-present 650 Industries. All rights reserved. 2 3 #import <React/RCTBridge.h> 4 #import <React/RCTBridgeModule.h> 5 6 #import "EXScopedBridgeModule.h" 7 8 // used for initializing scoped modules which don't tie in to any kernel service. 9 #define EX_KERNEL_SERVICE_NONE @"EXKernelServiceNone" 10 11 /** 12 * Use this in place of RCT_EXPORT_MODULE() to auto-init an instance of your scoped module on RCTBridge instances. 13 * @param js_name same as RCT_EXPORT_MODULE(), the module name available in JS 14 * @param kernel_service_class if specified, your module will be passed an unversioned instance of this kernel service at runtime. 15 * e.g. MyKernelService -> an instance of EXMyKernelService 16 */ 17 #define EX_EXPORT_SCOPED_MODULE(js_name, kernel_service_class) \ 18 RCT_EXTERN void EXRegisterScopedModule(Class, ...); \ 19 + (NSString *)moduleName { return @#js_name; } \ 20 + (void)load { EXRegisterScopedModule(self, @#kernel_service_class, nil); } 21 22 /** 23 * Use this in place of EX_EXPORT_SCOPED_MODULE() if the module requires more than one kernel service. 24 * @param js_name same as RCT_EXPORT_MODULE(), the module name available in JS 25 * @param ... strings representing names of kernel services to be passed to th emodule at runtime. 26 * e.g. @"MyKernelService" -> an instance of EXMyKernelService 27 */ 28 #define EX_EXPORT_SCOPED_MULTISERVICE_MODULE(js_name, ...) \ 29 RCT_EXTERN void EXRegisterScopedModule(Class, ...); \ 30 + (NSString *)moduleName { return @#js_name; } \ 31 + (void)load { EXRegisterScopedModule(self, __VA_ARGS__, nil); } 32 33 /** 34 * Provides a namespace/bottleneck through which scoped modules 35 * can make themselves accessible to other modules. 36 * 37 * e.g. EX_DECLARE_SCOPED_MODULE_GETTER(EXCoolClass, coolClass) 38 * provides the getter `_bridge.scopedModules.coolClass`. 39 */ 40 #define EX_DECLARE_SCOPED_MODULE_GETTER(className, getter) \ 41 @interface EXScopedModuleRegistry (className) \ 42 @property (nonatomic, readonly) className *__nonnull getter; \ 43 @end\ 44 45 /** 46 * Use in conjunction with EX_DECLARE_SCOPED_MODULE_GETTER, but in the corresponding implementation file. 47 */ 48 #define EX_DEFINE_SCOPED_MODULE_GETTER(className, getter) \ 49 @implementation EXScopedModuleRegistry (className) \ 50 - (className *)getter { return [self.bridge moduleForClass:[className class]]; } \ 51 @end\ 52 53 @interface EXScopedModuleRegistry : NSObject <RCTBridgeModule> 54 55 @end 56 57 @class RCTBridge; 58 59 @interface RCTBridge (EXScopedModuleRegistry) 60 61 @property (nonatomic, readonly) EXScopedModuleRegistry *scopedModules; 62 63 @end 64