Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ - (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
// Enable TurboModule interop by default in Bridgeless mode
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
RCTEnableTurboModuleInterop(YES);
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
RCTEnableTurboModuleInteropBridgeProxy(YES);

[self createReactHostIfNeeded:launchOptions
bundleConfiguration:bundleConfiguration
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ NSMutableArray<NSString *> *getModulesLoadedWithOldArch(void);
BOOL RCTTurboModuleEnabled(void);
void RCTEnableTurboModule(BOOL enabled);

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
// Turn on TurboModule interop
BOOL RCTTurboModuleInteropEnabled(void);
void RCTEnableTurboModuleInterop(BOOL enabled);
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

// Turn on the fabric interop layer
BOOL RCTFabricInteropLayerEnabled(void);
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void RCTEnableTurboModule(BOOL enabled)
// The new Architecture is enabled by default and we are ignoring changes to the TurboModule system.
}

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
static BOOL turboModuleInteropEnabled = NO;
BOOL RCTTurboModuleInteropEnabled(void)
{
Expand All @@ -208,6 +209,7 @@ void RCTEnableTurboModuleInterop(BOOL enabled)
{
turboModuleInteropEnabled = enabled;
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

static BOOL fabricInteropLayerEnabled = YES;
BOOL RCTFabricInteropLayerEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace facebook::react {

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
namespace {

class JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
Expand Down Expand Up @@ -93,6 +94,7 @@ class JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
}
};
} // namespace
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

TurboModuleManager::TurboModuleManager(
std::shared_ptr<CallInvoker> jsCallInvoker,
Expand Down Expand Up @@ -222,6 +224,7 @@ std::shared_ptr<TurboModule> TurboModuleManager::getTurboModule(
return nullptr;
}

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
TurboModuleProviderFunctionTypeWithRuntime
TurboModuleManager::createLegacyModuleProvider(
jni::alias_ref<jhybridobject> javaPart) {
Expand Down Expand Up @@ -318,14 +321,19 @@ std::shared_ptr<TurboModule> TurboModuleManager::getLegacyModule(

return nullptr;
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

void TurboModuleManager::installJSBindings(
jsi::Runtime& runtime,
jni::alias_ref<jhybridobject> javaPart) {
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
TurboModuleBinding::install(
runtime,
createTurboModuleProvider(javaPart),
createLegacyModuleProvider(javaPart));
#else
TurboModuleBinding::install(runtime, createTurboModuleProvider(javaPart));
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
}

void TurboModuleManager::dispatchJSBindingInstall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
* they want to be long-lived or short-lived.
*/
ModuleCache turboModuleCache_;
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
ModuleCache legacyModuleCache_;
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

explicit TurboModuleManager(
std::shared_ptr<CallInvoker> jsCallInvoker,
Expand All @@ -64,8 +66,10 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
std::shared_ptr<TurboModule>
getTurboModule(jni::alias_ref<jhybridobject> javaPart, const std::string &name, jsi::Runtime &runtime);

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
static TurboModuleProviderFunctionTypeWithRuntime createLegacyModuleProvider(jni::alias_ref<jhybridobject> javaPart);
std::shared_ptr<TurboModule> getLegacyModule(jni::alias_ref<jhybridobject> javaPart, const std::string &name);
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "JavaInteropTurboModule.h"

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP

namespace facebook::react {

namespace {
Expand Down Expand Up @@ -189,3 +191,5 @@ std::vector<facebook::jsi::PropNameID> JavaInteropTurboModule::getPropertyNames(
}

} // namespace facebook::react

#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP

#include <string>
#include <vector>

Expand Down Expand Up @@ -46,3 +48,5 @@ class JSI_EXPORT JavaInteropTurboModule : public JavaTurboModule {
};

} // namespace facebook::react

#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP

#import <string>
#import <vector>

Expand Down Expand Up @@ -88,3 +90,5 @@ class JSI_EXPORT ObjCInteropTurboModule : public ObjCTurboModule {
};

} // namespace facebook::react

#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "RCTInteropTurboModule.h"

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP

#import <objc/message.h>
#import <objc/runtime.h>

Expand Down Expand Up @@ -694,3 +696,5 @@ T RCTConvertTo(SEL selector, id json)
}

} // namespace facebook::react

#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ bool isTurboModuleClass(Class cls)
return [cls conformsToProtocol:@protocol(RCTTurboModule)];
}

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
bool isTurboModuleInstance(id module)
{
return isTurboModuleClass([module class]);
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

struct ModuleQueuePair {
id<RCTBridgeModule> module;
Expand Down Expand Up @@ -236,6 +238,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_sharedModuleQueue = dispatch_queue_create("com.meta.react.turbomodulemanager.queue", DISPATCH_QUEUE_SERIAL);
_devMenuConfigurationDecorator = devMenuConfigurationDecorator;

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
if (RCTTurboModuleInteropEnabled()) {
// TODO(T174674274): Implement lazy loading of legacy modules in the new architecture.
NSMutableDictionary<NSString *, id<RCTBridgeModule>> *legacyInitializedModules = [NSMutableDictionary new];
Expand All @@ -257,6 +260,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
}
_legacyEagerlyRegisteredModuleClasses = legacyEagerlyRegisteredModuleClasses;
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(bridgeWillInvalidateModules:)
Expand Down Expand Up @@ -418,6 +422,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
return nullptr;
}

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
- (std::shared_ptr<TurboModule>)provideLegacyModule:(const char *)moduleName
{
auto legacyModuleLookup = _legacyModuleCache.find(moduleName);
Expand Down Expand Up @@ -465,6 +470,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
_legacyModuleCache.insert({moduleName, turboModule});
return turboModule;
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

#pragma mark - Private Methods

Expand Down Expand Up @@ -492,9 +498,11 @@ - (BOOL)_isLegacyModuleClass:(Class)moduleClass
moduleProvider = [_delegate getModuleProvider:moduleName];
}

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
if (RCTTurboModuleInteropEnabled() && ![self _isTurboModule:moduleName] && !moduleProvider) {
return nil;
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

if (moduleProvider) {
if ([moduleProvider conformsToProtocol:@protocol(RCTTurboModule)]) {
Expand Down Expand Up @@ -631,9 +639,11 @@ - (ModuleHolder *)_getOrCreateModuleHolder:(const char *)moduleName

- (BOOL)_shouldCreateObjCModule:(Class)moduleClass
{
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
if (RCTTurboModuleInteropEnabled()) {
return [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)];
}
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

return [moduleClass conformsToProtocol:@protocol(RCTTurboModule)];
}
Expand Down Expand Up @@ -946,6 +956,7 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
return turboModule;
};

#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
if (RCTTurboModuleInteropEnabled()) {
auto legacyModuleProvider =
[self](jsi::Runtime & /*runtime*/, const std::string &name) -> std::shared_ptr<react::TurboModule> {
Expand All @@ -972,6 +983,9 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
} else {
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
}
#else
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
}

#pragma mark RCTTurboModuleRegistry
Expand Down
Loading