Skip to content

Commit

Permalink
Make sure to pass the BridgeProxy to view managers in the interop lay…
Browse files Browse the repository at this point in the history
…er (#45329)

Summary:
Pull Request resolved: #45329

Thanks to [#45232](#45232) we found a bug in the interop layer, where we were not passing the BridgeProxy in bridgeless mode to the view managers.

This Change should fix that issue.

## Changelog:
[iOS][Fixed] - Make sure to pass the RCTBridgeProxy to  ViewManagers

Reviewed By: dmytrorykun

Differential Revision: D59468292

fbshipit-source-id: 00666be21385a735878eb567c4b8a0986c609c5f
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jul 8, 2024
1 parent 6b7076e commit d6c90cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions packages/react-native/React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,20 @@ - (instancetype)initWithManagerClass:(Class)managerClass
return self;
}

- (BOOL)isBridgeMode
{
// If we are in bridge mode, the bridge is RCTBridge
// If we are bridgeless, the bridge is RCTBridgeProxy
return [_bridge isKindOfClass:[RCTBridge class]];
}

- (RCTViewManager *)manager
{
if (!_manager && _bridge) {
if (!_manager && [self isBridgeMode]) {
_manager = [_bridge moduleForClass:_managerClass];
} else if (!_manager && !_bridgelessViewManager) {
_bridgelessViewManager = [_managerClass new];
_bridgelessViewManager.bridge = _bridge;
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
object:nil
userInfo:@{@"module" : _bridgelessViewManager}];
Expand Down Expand Up @@ -265,8 +273,8 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView
type == NSSelectorFromString(@"RCTDirectEventBlock:") ||
type == NSSelectorFromString(@"RCTCapturingEventBlock:")) {
// Special case for event handlers
setterBlock =
createEventSetter(name, setter, self.eventInterceptor, _bridge ? _bridge.eventDispatcher : _eventDispatcher);
setterBlock = createEventSetter(
name, setter, self.eventInterceptor, [self isBridgeMode] ? _bridge.eventDispatcher : _eventDispatcher);
} else {
// Ordinary property handlers
NSMethodSignature *typeSignature = [[RCTConvert class] methodSignatureForSelector:type];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
bridgeModuleDecorator = unwrapManagedObject(optionalModuleDecorator.value());
}

RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:viewManagerClass
bridge:bridge
eventDispatcher:eventDispatcher];
RCTComponentData *componentData =
[[RCTComponentData alloc] initWithManagerClass:viewManagerClass
bridge:bridge != nil ? bridge : (RCTBridge *)bridgeProxy
eventDispatcher:eventDispatcher];
return wrapManagedObject([[RCTLegacyViewManagerInteropCoordinator alloc]
initWithComponentData:componentData
bridge:bridge
Expand Down

0 comments on commit d6c90cf

Please sign in to comment.