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