diff --git a/React/Base/RCTBridge+Private.h b/React/Base/RCTBridge+Private.h index 1995801ff..d53cd0e83 100644 --- a/React/Base/RCTBridge+Private.h +++ b/React/Base/RCTBridge+Private.h @@ -21,6 +21,8 @@ RCT_EXTERN __attribute__((weak)) void RCTFBQuickPerformanceLoggerConfigureHooks( RCT_EXTERN void RCTVerifyAllModulesExported(NSArray *extraModules); #endif +RCT_EXTERN void RCTRegisterModule(Class); + @interface RCTBridge () // Private designated initializer diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index 75908a1b0..1da937e8d 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -73,6 +73,16 @@ RCT_EXTERN void RCTRegisterModule(Class); \ + (NSString *)moduleName { return @#js_name; } \ + (void)load { RCTRegisterModule(self); } +/** + * To improve startup performance users may want to generate their module lists + * at build time and hook the delegate to merge with the runtime list. This + * macro takes the place of the above for those cases by omitting the +load + * generation. + * + */ +#define RCT_EXPORT_PRE_REGISTERED_MODULE(js_name) \ ++ (NSString *)moduleName { return @#js_name; } + // Implemented by RCT_EXPORT_MODULE + (NSString *)moduleName; diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 7d290fab5..2c089b007 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -650,8 +650,8 @@ struct RCTInstanceCallback : public InstanceCallback { // Set up moduleData for automatically-exported modules NSArray *moduleDataById = [self registerModulesForClasses:modules]; -#ifdef RCT_DEBUG if (lazilyDiscovered) { +#ifdef RCT_DEBUG // Lazily discovered modules do not require instantiation here, // as they are not allowed to have pre-instantiated instance // and must not require the main queue. @@ -659,10 +659,8 @@ struct RCTInstanceCallback : public InstanceCallback { RCTAssert(!(moduleData.requiresMainQueueSetup || moduleData.hasInstance), @"Module \'%@\' requires initialization on the Main Queue or has pre-instantiated, which is not supported for the lazily discovered modules.", moduleData.name); } - } - else #endif - { + } else { RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge initModulesWithDispatchGroup:] moduleData.hasInstance", nil); // Dispatch module init onto main thread for those modules that require it