From f8929f8d548cd515398c55b282f033fb9d03d7ef Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 10 May 2023 15:58:13 -0700 Subject: [PATCH] Allow the TurboModule system to create legacy modules (#37364) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37364 When the TurboModule interop layer is enabled, it should create modules that conform to RCTBridgeModule (i.e: legacy and turbo modules). When the TurboModule interop layer is disabled, it should only create modules that conform to RCTTurboModule (i.e: turbo modules). Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D45706884 fbshipit-source-id: be6f054556d1506e2934884ab5014394f0c08e8f --- .../platform/ios/ReactCommon/RCTTurboModuleManager.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 a961b31b4ec..2319a9c0d6d 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 @@ -420,7 +420,7 @@ static Class getFallbackClassFromName(const char *name) __block id module = nil; - if ([moduleClass conformsToProtocol:@protocol(RCTTurboModule)]) { + if ([self _shouldCreateObjCModule:moduleClass]) { __weak __typeof(self) weakSelf = self; dispatch_block_t work = ^{ auto strongSelf = weakSelf; @@ -478,6 +478,15 @@ static Class getFallbackClassFromName(const char *name) return moduleHolder->getModule(); } +- (BOOL)_shouldCreateObjCModule:(Class)moduleClass +{ + if (RCTTurboModuleInteropEnabled()) { + return [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)]; + } + + return [moduleClass conformsToProtocol:@protocol(RCTTurboModule)]; +} + /** * Given a NativeModule class, and its name, create and initialize it synchronously. *