Remove bridge mode from view manager interop (#59262)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/59262

The interop layer only ever receives a bridge proxy, so delete the unused bridge ivar, init parameter, and bridge-only command paths. Keep the bridgeless flows and the proxy injection that legacy managers rely on.

Changelog:
[Internal]

Reviewed By: shwanton

Differential Revision: D126575534

fbshipit-source-id: de23006d517cc577b6623cb26d41cbe5a2162fad
This commit is contained in:
Christoph Purrer authored and meta-codesync[bot] committed 2026-10-22 19:55:29 -07:00
1 parent 0876643b91
commit 797882ef98
3 files changed
+12 -70

No files matched your search

@@ -75,7 +75,7 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
return nil;
}
static Class getViewManagerClass(const std::string &componentName, RCTBridge *bridge, RCTBridgeProxy *bridgeProxy)
static Class getViewManagerClass(const std::string &componentName, RCTBridgeProxy *bridgeProxy)
{
Class viewManager = getViewManagerFromComponentName(componentName);
if (viewManager != nil) {
@@ -90,11 +90,7 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
}
}
} else {
// If all the heuristics fail, let's try to retrieve the view manager from the bridge/bridgeProxy
if (bridge != nil) {
return [[bridge moduleForName:RCTNSStringFromString(componentName)] class];
}
// If all the heuristics fail, let's try to retrieve the view manager from the bridge proxy
if (bridgeProxy != nil) {
return [[bridgeProxy moduleForName:RCTNSStringFromString(componentName) lazilyLoadIfNecessary:YES] class];
}
@@ -107,12 +103,6 @@ static std::shared_ptr<void> constructCoordinator(
const std::shared_ptr<const ContextContainer> &contextContainer,
const ComponentDescriptor::Flavor &flavor)
{
auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
RCTBridge *bridge;
if (optionalBridge) {
bridge = unwrapManagedObjectWeakly(optionalBridge.value());
}
RCTBridgeProxy *bridgeProxy;
auto optionalBridgeProxy = contextContainer->find<std::shared_ptr<void>>("RCTBridgeProxy");
if (optionalBridgeProxy) {
@@ -120,7 +110,7 @@ static std::shared_ptr<void> constructCoordinator(
}
auto componentName = *std::static_pointer_cast<const std::string>(flavor);
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
Class viewManagerClass = getViewManagerClass(componentName, bridgeProxy);
assert(viewManagerClass);
auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
@@ -135,13 +125,11 @@ static std::shared_ptr<void> constructCoordinator(
bridgeModuleDecorator = unwrapManagedObject(optionalModuleDecorator.value());
}
RCTComponentData *componentData =
[[RCTComponentData alloc] initWithManagerClass:viewManagerClass
bridge:bridge != nil ? bridge : (RCTBridge *)bridgeProxy
eventDispatcher:eventDispatcher];
RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:viewManagerClass
bridge:(RCTBridge *)bridgeProxy
eventDispatcher:eventDispatcher];
return wrapManagedObject([[RCTLegacyViewManagerInteropCoordinator alloc]
initWithComponentData:componentData
bridge:bridge
bridgeProxy:bridgeProxy
bridgelessInteropData:bridgeModuleDecorator]);
}
@@ -25,7 +25,6 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic &&event);
@interface RCTLegacyViewManagerInteropCoordinator : NSObject
- (instancetype)initWithComponentData:(RCTComponentData *)componentData
bridge:(nullable RCTBridge *)bridge
bridgeProxy:(nullable RCTBridgeProxy *)bridgeProxy
bridgelessInteropData:(RCTBridgeModuleDecorator *)bridgelessInteropData;
@@ -28,7 +28,6 @@ using namespace facebook::react;
@implementation RCTLegacyViewManagerInteropCoordinator {
RCTComponentData *_componentData;
__weak RCTBridge *_bridge;
__weak RCTBridgeModuleDecorator *_bridgelessInteropData;
__weak RCTBridgeProxy *_bridgeProxy;
@@ -47,23 +46,14 @@ using namespace facebook::react;
}
- (instancetype)initWithComponentData:(RCTComponentData *)componentData
bridge:(nullable RCTBridge *)bridge
bridgeProxy:(nullable RCTBridgeProxy *)bridgeProxy
bridgelessInteropData:(RCTBridgeModuleDecorator *)bridgelessInteropData
{
if (self = [super init]) {
_componentData = componentData;
_bridge = bridge;
_bridgelessInteropData = bridgelessInteropData;
_bridgeProxy = bridgeProxy;
if (bridgelessInteropData) {
// During bridge mode, RCTBridgeModules will be decorated with these APIs by the bridge.
RCTAssert(
_bridge == nil,
@"RCTLegacyViewManagerInteropCoordinator should not be initialized with RCTBridgeModuleDecorator in bridge mode.");
}
_eventInterceptors = [NSMutableDictionary new];
__weak __typeof(self) weakSelf = self;
@@ -117,9 +107,7 @@ using namespace facebook::react;
reactTag:(NSInteger)tag
paperView:(nonnull UIView *)paperView
{
Class managerClass = _componentData.managerClass;
[self _lookupModuleMethodsIfNecessary];
RCTModuleData *moduleData = [_bridge.batchedBridge moduleDataForName:RCTBridgeModuleNameForClass(managerClass)];
id<RCTBridgeMethod> method;
// We can't use `[NSString intValue]` as "0" is a valid command,
@@ -129,9 +117,9 @@ using namespace facebook::react;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
if ([commandName isKindOfClass:[NSNumber class]] || [formatter numberFromString:commandName] != NULL) {
method = moduleData ? moduleData.methods[[commandName intValue]] : _moduleMethods[[commandName intValue]];
method = _moduleMethods[[commandName intValue]];
} else if ([commandName isKindOfClass:[NSString class]]) {
method = moduleData ? moduleData.methodsByName[commandName] : _moduleMethodsByName[commandName];
method = _moduleMethodsByName[commandName];
if (method == nil) {
RCTLogError(@"No command found with name \"%@\"", commandName);
}
@@ -142,26 +130,6 @@ using namespace facebook::react;
NSArray *newArgs = [@[ [NSNumber numberWithInteger:tag] ] arrayByAddingObjectsFromArray:args];
if (_bridge) {
[self _handleCommandsOnBridge:method withArgs:newArgs];
} else {
[self _handleCommandsOnBridgeless:method withArgs:newArgs];
}
}
#pragma mark - Private
- (void)_handleCommandsOnBridge:(id<RCTBridgeMethod>)method withArgs:(NSArray *)newArgs
{
[_bridge.batchedBridge
dispatchBlock:^{
[method invokeWithBridge:self->_bridge module:self->_componentData.manager arguments:newArgs];
[self->_bridge.uiManager setNeedsLayout];
}
queue:RCTGetUIManagerQueue()];
}
- (void)_handleCommandsOnBridgeless:(id<RCTBridgeMethod>)method withArgs:(NSArray *)newArgs
{
RCTViewManager *componentViewManager = self->_componentData.manager;
[componentViewManager setValue:_bridgeProxy forKey:@"bridge"];
@@ -171,30 +139,17 @@ using namespace facebook::react;
}];
}
#pragma mark - Private
- (void)_addUIBlock:(RCTViewManagerUIBlock)block
{
if (_bridge) {
[self _addUIBlockOnBridge:block];
} else {
[self->_bridgeProxy.uiManager addUIBlock:block];
}
}
- (void)_addUIBlockOnBridge:(RCTViewManagerUIBlock)block
{
__weak __typeof__(self) weakSelf = self;
[_bridge.batchedBridge
dispatchBlock:^{
__typeof__(self) strongSelf = weakSelf;
[strongSelf->_bridge.uiManager addUIBlock:block];
}
queue:RCTGetUIManagerQueue()];
[self->_bridgeProxy.uiManager addUIBlock:block];
}
// This is copy-pasta from RCTModuleData.
- (void)_lookupModuleMethodsIfNecessary
{
if (!_bridge && !_moduleMethods) {
if (!_moduleMethods) {
_moduleMethods = [NSMutableArray new];
_moduleMethodsByName = [NSMutableDictionary new];