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
This commit is contained in:
Ramanpreet Nara
2023-05-10 15:58:13 -07:00
committed by Facebook GitHub Bot
parent 16a250eb13
commit f8929f8d54
@@ -420,7 +420,7 @@ static Class getFallbackClassFromName(const char *name)
__block id<RCTBridgeModule> 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.
*