From 9e5c963e2dbd90dbf2d260b67c2897e924be066e Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Mon, 17 Apr 2023 19:33:02 -0700 Subject: [PATCH] pass eager initialized modules directly to bridge (#36916) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36916 Changelog: [iOS][Removed] the bridge only behavior of eager initialization of native modules was coupled with the turbomodule infra, even though it didn't need to be. this eager initialized modules is a static list, and the bridge owner which is usually app scoped, can pass this list directly to the bridge instead. Reviewed By: sammy-SC Differential Revision: D45021784 fbshipit-source-id: f033661e0722f65ae971bd7ce27f8dc7de1173ad --- .../React/Base/RCTBridge+Private.h | 3 +++ .../React/Base/RCTTurboModuleRegistry.h | 3 --- .../React/CxxBridge/RCTCxxBridge.mm | 4 ++-- .../ios/ReactCommon/RCTTurboModuleManager.h | 2 -- .../ios/ReactCommon/RCTTurboModuleManager.mm | 18 ------------------ 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/react-native/React/Base/RCTBridge+Private.h b/packages/react-native/React/Base/RCTBridge+Private.h index fc4639dec0a..4664278d812 100644 --- a/packages/react-native/React/Base/RCTBridge+Private.h +++ b/packages/react-native/React/Base/RCTBridge+Private.h @@ -70,6 +70,9 @@ RCT_EXTERN void RCTRegisterModule(Class); */ @property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry; +@property (nonatomic, copy, readwrite) NSArray *eagerInitModuleNames_DO_NOT_USE; +@property (nonatomic, copy, readwrite) NSArray *eagerInitMainQueueModuleNames_DO_NOT_USE; + @end @interface RCTBridge (RCTCxxBridge) diff --git a/packages/react-native/React/Base/RCTTurboModuleRegistry.h b/packages/react-native/React/Base/RCTTurboModuleRegistry.h index c0a6f52759a..8ad5d06af11 100644 --- a/packages/react-native/React/Base/RCTTurboModuleRegistry.h +++ b/packages/react-native/React/Base/RCTTurboModuleRegistry.h @@ -23,7 +23,4 @@ */ - (id)moduleForName:(const char *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure; - (BOOL)moduleIsInitialized:(const char *)moduleName; - -- (NSArray *)eagerInitModuleNames; -- (NSArray *)eagerInitMainQueueModuleNames; @end diff --git a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm index 5cec2735d44..45c29a24fc9 100644 --- a/packages/react-native/React/CxxBridge/RCTCxxBridge.mm +++ b/packages/react-native/React/CxxBridge/RCTCxxBridge.mm @@ -448,11 +448,11 @@ struct RCTInstanceCallback : public InstanceCallback { * RCTCxxBridge If id is assigned by this time, eagerly initialize all TurboModules */ if (_turboModuleRegistry && RCTTurboModuleEagerInitEnabled()) { - for (NSString *moduleName in [_turboModuleRegistry eagerInitModuleNames]) { + for (NSString *moduleName in [_parentBridge eagerInitModuleNames_DO_NOT_USE]) { [_turboModuleRegistry moduleForName:[moduleName UTF8String]]; } - for (NSString *moduleName in [_turboModuleRegistry eagerInitMainQueueModuleNames]) { + for (NSString *moduleName in [_parentBridge eagerInitMainQueueModuleNames_DO_NOT_USE]) { if (RCTIsMainQueue()) { [_turboModuleRegistry moduleForName:[moduleName UTF8String]]; } else { diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h index 2124e05ac01..c129391fa90 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h @@ -20,8 +20,6 @@ RCT_EXTERN void RCTTurboModuleSetBindingMode(facebook::react::TurboModuleBinding @protocol RCTTurboModuleManagerDelegate @optional -- (NSArray *)getEagerInitModuleNames; -- (NSArray *)getEagerInitMainQueueModuleNames; /** * Given a module name, return its actual class. If not provided, basic ObjC class lookup is performed. diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index 9bfea510a57..5d7e84f1446 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -775,24 +775,6 @@ static Class getFallbackClassFromName(const char *name) return _turboModuleHolders.find(moduleName) != _turboModuleHolders.end(); } -- (NSArray *)eagerInitModuleNames -{ - if ([_delegate respondsToSelector:@selector(getEagerInitModuleNames)]) { - return [_delegate getEagerInitModuleNames]; - } - - return @[]; -} - -- (NSArray *)eagerInitMainQueueModuleNames -{ - if ([_delegate respondsToSelector:@selector(getEagerInitMainQueueModuleNames)]) { - return [_delegate getEagerInitMainQueueModuleNames]; - } - - return @[]; -} - #pragma mark Invalidation logic - (void)bridgeWillInvalidateModules:(NSNotification *)notification