Skip to content

Commit 82c4ed3

Browse files
Enable TurboModule interop layer opt out via RCT_REMOVE_LEGACY_INTEROP (#56984)
Summary: Changelog: [Internal][General] Enable TurboModule interop layer opt out via RCT_REMOVE_LEGACY_INTEROP Differential Revision: D106109160
1 parent 9ac12ce commit 82c4ed3

10 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ - (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
152152
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
153153
{
154154
// Enable TurboModule interop by default in Bridgeless mode
155+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
155156
RCTEnableTurboModuleInterop(YES);
157+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
158+
RCTEnableTurboModuleInteropBridgeProxy(YES);
156159

157160
[self createReactHostIfNeeded:launchOptions
158161
bundleConfiguration:bundleConfiguration

packages/react-native/React/Base/RCTBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ NSMutableArray<NSString *> *getModulesLoadedWithOldArch(void);
5050
BOOL RCTTurboModuleEnabled(void);
5151
void RCTEnableTurboModule(BOOL enabled);
5252

53+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
5354
// Turn on TurboModule interop
5455
BOOL RCTTurboModuleInteropEnabled(void);
5556
void RCTEnableTurboModuleInterop(BOOL enabled);
57+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
5658

5759
// Turn on the fabric interop layer
5860
BOOL RCTFabricInteropLayerEnabled(void);

packages/react-native/React/Base/RCTBridge.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void RCTEnableTurboModule(BOOL enabled)
199199
// The new Architecture is enabled by default and we are ignoring changes to the TurboModule system.
200200
}
201201

202+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
202203
static BOOL turboModuleInteropEnabled = NO;
203204
BOOL RCTTurboModuleInteropEnabled(void)
204205
{
@@ -208,6 +209,7 @@ void RCTEnableTurboModuleInterop(BOOL enabled)
208209
{
209210
turboModuleInteropEnabled = enabled;
210211
}
212+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
211213

212214
static BOOL fabricInteropLayerEnabled = YES;
213215
BOOL RCTFabricInteropLayerEnabled()

packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace facebook::react {
2626

27+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
2728
namespace {
2829

2930
class JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
@@ -93,6 +94,7 @@ class JMethodDescriptor : public jni::JavaClass<JMethodDescriptor> {
9394
}
9495
};
9596
} // namespace
97+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
9698

9799
TurboModuleManager::TurboModuleManager(
98100
std::shared_ptr<CallInvoker> jsCallInvoker,
@@ -222,6 +224,7 @@ std::shared_ptr<TurboModule> TurboModuleManager::getTurboModule(
222224
return nullptr;
223225
}
224226

227+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
225228
TurboModuleProviderFunctionTypeWithRuntime
226229
TurboModuleManager::createLegacyModuleProvider(
227230
jni::alias_ref<jhybridobject> javaPart) {
@@ -318,14 +321,19 @@ std::shared_ptr<TurboModule> TurboModuleManager::getLegacyModule(
318321

319322
return nullptr;
320323
}
324+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
321325

322326
void TurboModuleManager::installJSBindings(
323327
jsi::Runtime& runtime,
324328
jni::alias_ref<jhybridobject> javaPart) {
329+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
325330
TurboModuleBinding::install(
326331
runtime,
327332
createTurboModuleProvider(javaPart),
328333
createLegacyModuleProvider(javaPart));
334+
#else
335+
TurboModuleBinding::install(runtime, createTurboModuleProvider(javaPart));
336+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
329337
}
330338

331339
void TurboModuleManager::dispatchJSBindingInstall(

packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
4848
* they want to be long-lived or short-lived.
4949
*/
5050
ModuleCache turboModuleCache_;
51+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
5152
ModuleCache legacyModuleCache_;
53+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
5254

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

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

7175
} // namespace facebook::react

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "JavaInteropTurboModule.h"
99

10+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
11+
1012
namespace facebook::react {
1113

1214
namespace {
@@ -189,3 +191,5 @@ std::vector<facebook::jsi::PropNameID> JavaInteropTurboModule::getPropertyNames(
189191
}
190192

191193
} // namespace facebook::react
194+
195+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
11+
1012
#include <string>
1113
#include <vector>
1214

@@ -46,3 +48,5 @@ class JSI_EXPORT JavaInteropTurboModule : public JavaTurboModule {
4648
};
4749

4850
} // namespace facebook::react
51+
52+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
11+
1012
#import <string>
1113
#import <vector>
1214

@@ -88,3 +90,5 @@ class JSI_EXPORT ObjCInteropTurboModule : public ObjCTurboModule {
8890
};
8991

9092
} // namespace facebook::react
93+
94+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "RCTInteropTurboModule.h"
99

10+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
11+
1012
#import <objc/message.h>
1113
#import <objc/runtime.h>
1214

@@ -694,3 +696,5 @@ T RCTConvertTo(SEL selector, id json)
694696
}
695697

696698
} // namespace facebook::react
699+
700+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ bool isTurboModuleClass(Class cls)
161161
return [cls conformsToProtocol:@protocol(RCTTurboModule)];
162162
}
163163

164+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
164165
bool isTurboModuleInstance(id module)
165166
{
166167
return isTurboModuleClass([module class]);
167168
}
169+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
168170

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

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

261265
[[NSNotificationCenter defaultCenter] addObserver:self
262266
selector:@selector(bridgeWillInvalidateModules:)
@@ -418,6 +422,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
418422
return nullptr;
419423
}
420424

425+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
421426
- (std::shared_ptr<TurboModule>)provideLegacyModule:(const char *)moduleName
422427
{
423428
auto legacyModuleLookup = _legacyModuleCache.find(moduleName);
@@ -465,6 +470,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
465470
_legacyModuleCache.insert({moduleName, turboModule});
466471
return turboModule;
467472
}
473+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
468474

469475
#pragma mark - Private Methods
470476

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

501+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
495502
if (RCTTurboModuleInteropEnabled() && ![self _isTurboModule:moduleName] && !moduleProvider) {
496503
return nil;
497504
}
505+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
498506

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

632640
- (BOOL)_shouldCreateObjCModule:(Class)moduleClass
633641
{
642+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
634643
if (RCTTurboModuleInteropEnabled()) {
635644
return [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)];
636645
}
646+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
637647

638648
return [moduleClass conformsToProtocol:@protocol(RCTTurboModule)];
639649
}
@@ -946,6 +956,7 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
946956
return turboModule;
947957
};
948958

959+
#ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
949960
if (RCTTurboModuleInteropEnabled()) {
950961
auto legacyModuleProvider =
951962
[self](jsi::Runtime & /*runtime*/, const std::string &name) -> std::shared_ptr<react::TurboModule> {
@@ -972,6 +983,9 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
972983
} else {
973984
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
974985
}
986+
#else
987+
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
988+
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
975989
}
976990

977991
#pragma mark RCTTurboModuleRegistry

0 commit comments

Comments
 (0)