Skip to content

Commit 797882e

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Remove bridge mode from view manager interop (#59262)
Summary: Pull Request resolved: #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
1 parent 0876643 commit 797882e

3 files changed

Lines changed: 12 additions & 70 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
7575
return nil;
7676
}
7777

78-
static Class getViewManagerClass(const std::string &componentName, RCTBridge *bridge, RCTBridgeProxy *bridgeProxy)
78+
static Class getViewManagerClass(const std::string &componentName, RCTBridgeProxy *bridgeProxy)
7979
{
8080
Class viewManager = getViewManagerFromComponentName(componentName);
8181
if (viewManager != nil) {
@@ -90,11 +90,7 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
9090
}
9191
}
9292
} else {
93-
// If all the heuristics fail, let's try to retrieve the view manager from the bridge/bridgeProxy
94-
if (bridge != nil) {
95-
return [[bridge moduleForName:RCTNSStringFromString(componentName)] class];
96-
}
97-
93+
// If all the heuristics fail, let's try to retrieve the view manager from the bridge proxy
9894
if (bridgeProxy != nil) {
9995
return [[bridgeProxy moduleForName:RCTNSStringFromString(componentName) lazilyLoadIfNecessary:YES] class];
10096
}
@@ -107,20 +103,14 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
107103
const std::shared_ptr<const ContextContainer> &contextContainer,
108104
const ComponentDescriptor::Flavor &flavor)
109105
{
110-
auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
111-
RCTBridge *bridge;
112-
if (optionalBridge) {
113-
bridge = unwrapManagedObjectWeakly(optionalBridge.value());
114-
}
115-
116106
RCTBridgeProxy *bridgeProxy;
117107
auto optionalBridgeProxy = contextContainer->find<std::shared_ptr<void>>("RCTBridgeProxy");
118108
if (optionalBridgeProxy) {
119109
bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
120110
}
121111

122112
auto componentName = *std::static_pointer_cast<const std::string>(flavor);
123-
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
113+
Class viewManagerClass = getViewManagerClass(componentName, bridgeProxy);
124114
assert(viewManagerClass);
125115

126116
auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
@@ -135,13 +125,11 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
135125
bridgeModuleDecorator = unwrapManagedObject(optionalModuleDecorator.value());
136126
}
137127

138-
RCTComponentData *componentData =
139-
[[RCTComponentData alloc] initWithManagerClass:viewManagerClass
140-
bridge:bridge != nil ? bridge : (RCTBridge *)bridgeProxy
141-
eventDispatcher:eventDispatcher];
128+
RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:viewManagerClass
129+
bridge:(RCTBridge *)bridgeProxy
130+
eventDispatcher:eventDispatcher];
142131
return wrapManagedObject([[RCTLegacyViewManagerInteropCoordinator alloc]
143132
initWithComponentData:componentData
144-
bridge:bridge
145133
bridgeProxy:bridgeProxy
146134
bridgelessInteropData:bridgeModuleDecorator]);
147135
}

‎packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic &&event);
2525
@interface RCTLegacyViewManagerInteropCoordinator : NSObject
2626

2727
- (instancetype)initWithComponentData:(RCTComponentData *)componentData
28-
bridge:(nullable RCTBridge *)bridge
2928
bridgeProxy:(nullable RCTBridgeProxy *)bridgeProxy
3029
bridgelessInteropData:(RCTBridgeModuleDecorator *)bridgelessInteropData;
3130

‎packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm‎

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
@implementation RCTLegacyViewManagerInteropCoordinator {
3030
RCTComponentData *_componentData;
31-
__weak RCTBridge *_bridge;
3231
__weak RCTBridgeModuleDecorator *_bridgelessInteropData;
3332
__weak RCTBridgeProxy *_bridgeProxy;
3433

@@ -47,23 +46,14 @@ @implementation RCTLegacyViewManagerInteropCoordinator {
4746
}
4847

4948
- (instancetype)initWithComponentData:(RCTComponentData *)componentData
50-
bridge:(nullable RCTBridge *)bridge
5149
bridgeProxy:(nullable RCTBridgeProxy *)bridgeProxy
5250
bridgelessInteropData:(RCTBridgeModuleDecorator *)bridgelessInteropData
5351
{
5452
if (self = [super init]) {
5553
_componentData = componentData;
56-
_bridge = bridge;
5754
_bridgelessInteropData = bridgelessInteropData;
5855
_bridgeProxy = bridgeProxy;
5956

60-
if (bridgelessInteropData) {
61-
// During bridge mode, RCTBridgeModules will be decorated with these APIs by the bridge.
62-
RCTAssert(
63-
_bridge == nil,
64-
@"RCTLegacyViewManagerInteropCoordinator should not be initialized with RCTBridgeModuleDecorator in bridge mode.");
65-
}
66-
6757
_eventInterceptors = [NSMutableDictionary new];
6858

6959
__weak __typeof(self) weakSelf = self;
@@ -117,9 +107,7 @@ - (void)handleCommand:(NSString *)commandName
117107
reactTag:(NSInteger)tag
118108
paperView:(nonnull UIView *)paperView
119109
{
120-
Class managerClass = _componentData.managerClass;
121110
[self _lookupModuleMethodsIfNecessary];
122-
RCTModuleData *moduleData = [_bridge.batchedBridge moduleDataForName:RCTBridgeModuleNameForClass(managerClass)];
123111
id<RCTBridgeMethod> method;
124112

125113
// We can't use `[NSString intValue]` as "0" is a valid command,
@@ -129,9 +117,9 @@ - (void)handleCommand:(NSString *)commandName
129117
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
130118

131119
if ([commandName isKindOfClass:[NSNumber class]] || [formatter numberFromString:commandName] != NULL) {
132-
method = moduleData ? moduleData.methods[[commandName intValue]] : _moduleMethods[[commandName intValue]];
120+
method = _moduleMethods[[commandName intValue]];
133121
} else if ([commandName isKindOfClass:[NSString class]]) {
134-
method = moduleData ? moduleData.methodsByName[commandName] : _moduleMethodsByName[commandName];
122+
method = _moduleMethodsByName[commandName];
135123
if (method == nil) {
136124
RCTLogError(@"No command found with name \"%@\"", commandName);
137125
}
@@ -142,26 +130,6 @@ - (void)handleCommand:(NSString *)commandName
142130

143131
NSArray *newArgs = [@[ [NSNumber numberWithInteger:tag] ] arrayByAddingObjectsFromArray:args];
144132

145-
if (_bridge) {
146-
[self _handleCommandsOnBridge:method withArgs:newArgs];
147-
} else {
148-
[self _handleCommandsOnBridgeless:method withArgs:newArgs];
149-
}
150-
}
151-
152-
#pragma mark - Private
153-
- (void)_handleCommandsOnBridge:(id<RCTBridgeMethod>)method withArgs:(NSArray *)newArgs
154-
{
155-
[_bridge.batchedBridge
156-
dispatchBlock:^{
157-
[method invokeWithBridge:self->_bridge module:self->_componentData.manager arguments:newArgs];
158-
[self->_bridge.uiManager setNeedsLayout];
159-
}
160-
queue:RCTGetUIManagerQueue()];
161-
}
162-
163-
- (void)_handleCommandsOnBridgeless:(id<RCTBridgeMethod>)method withArgs:(NSArray *)newArgs
164-
{
165133
RCTViewManager *componentViewManager = self->_componentData.manager;
166134
[componentViewManager setValue:_bridgeProxy forKey:@"bridge"];
167135

@@ -171,30 +139,17 @@ - (void)_handleCommandsOnBridgeless:(id<RCTBridgeMethod>)method withArgs:(NSArra
171139
}];
172140
}
173141

174-
- (void)_addUIBlock:(RCTViewManagerUIBlock)block
175-
{
176-
if (_bridge) {
177-
[self _addUIBlockOnBridge:block];
178-
} else {
179-
[self->_bridgeProxy.uiManager addUIBlock:block];
180-
}
181-
}
142+
#pragma mark - Private
182143

183-
- (void)_addUIBlockOnBridge:(RCTViewManagerUIBlock)block
144+
- (void)_addUIBlock:(RCTViewManagerUIBlock)block
184145
{
185-
__weak __typeof__(self) weakSelf = self;
186-
[_bridge.batchedBridge
187-
dispatchBlock:^{
188-
__typeof__(self) strongSelf = weakSelf;
189-
[strongSelf->_bridge.uiManager addUIBlock:block];
190-
}
191-
queue:RCTGetUIManagerQueue()];
146+
[self->_bridgeProxy.uiManager addUIBlock:block];
192147
}
193148

194149
// This is copy-pasta from RCTModuleData.
195150
- (void)_lookupModuleMethodsIfNecessary
196151
{
197-
if (!_bridge && !_moduleMethods) {
152+
if (!_moduleMethods) {
198153
_moduleMethods = [NSMutableArray new];
199154
_moduleMethodsByName = [NSMutableDictionary new];
200155

0 commit comments

Comments
 (0)