Skip to content

Commit 3d9b943

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Delete TurboModule interop layer (probe diff, do not land)
Summary: Deletes the iOS TurboModule interop layer outright as a probe to surface every remaining iOS-side dependent module and component. The interop layer is the shim that exposes legacy `RCTBridgeModule` instances to the new-arch TurboModule registry; with the legacy architecture being removed from React Native, every consumer of this shim needs to be migrated to a real TurboModule before the legacy arch can be deleted. This change is intentionally not safe to land. It is meant to be built locally so that the resulting compile errors enumerate the iOS modules and components that still need to be migrated. The Android-side interop layer (`JavaInteropTurboModule.{h,cpp}`, `TurboModuleInteropUtils.kt`, `InteropModuleRegistry.kt`, and its test) is intentionally retained in this iteration — Android migration is being tracked separately. iOS files removed: - `ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.h` - `ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTInteropTurboModule.mm` LegacyViewManager view interop, fabric UIBlock interop, and InteropEventEmitter are out of scope for this probe and remain in place. Changelog: [Internal][General]Delete TurboModule interop layer Differential Revision: D106109160
1 parent 8447464 commit 3d9b943

7 files changed

Lines changed: 38 additions & 0 deletions

File tree

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_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_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_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_INTEROP
321325

322326
void TurboModuleManager::installJSBindings(
323327
jsi::Runtime& runtime,
324328
jni::alias_ref<jhybridobject> javaPart) {
329+
#ifndef RCT_REMOVE_LEGACY_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_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_INTEROP
5152
ModuleCache legacyModuleCache_;
53+
#endif // RCT_REMOVE_LEGACY_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_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_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_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_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_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_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_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_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_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_INTEROP

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

Lines changed: 10 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_INTEROP
164165
bool isTurboModuleInstance(id module)
165166
{
166167
return isTurboModuleClass([module class]);
167168
}
169+
#endif // RCT_REMOVE_LEGACY_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_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_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_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_INTEROP
468474

469475
#pragma mark - Private Methods
470476

@@ -946,6 +952,7 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
946952
return turboModule;
947953
};
948954

955+
#ifndef RCT_REMOVE_LEGACY_INTEROP
949956
if (RCTTurboModuleInteropEnabled()) {
950957
auto legacyModuleProvider =
951958
[self](jsi::Runtime & /*runtime*/, const std::string &name) -> std::shared_ptr<react::TurboModule> {
@@ -972,6 +979,9 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime
972979
} else {
973980
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
974981
}
982+
#else
983+
TurboModuleBinding::install(runtime, std::move(turboModuleProvider));
984+
#endif // RCT_REMOVE_LEGACY_INTEROP
975985
}
976986

977987
#pragma mark RCTTurboModuleRegistry

0 commit comments

Comments
 (0)