Skip to content

Commit c45845d

Browse files
committed
Make the interop-layer work with components with custom name
1 parent 5929a06 commit c45845d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ @implementation RCTLegacyInteropComponents
1111

1212
+ (NSArray<NSString *> *)legacyInteropComponents
1313
{
14-
return @[ @"RNTMyLegacyNativeView", @"RNTMyNativeView" ];
14+
return @[
15+
@"RNTMyLegacyNativeView",
16+
@"RNTMyNativeView"
17+
];
1518
}
1619

1720
@end

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,28 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
7474
return nil;
7575
}
7676

77+
static Class getViewManagerClass(const std::string &componentName, RCTBridge * bridge, RCTBridgeProxy * bridgeProxy) {
78+
Class viewManager = getViewManagerFromComponentName(componentName);
79+
if (viewManager != nil) {
80+
return viewManager;
81+
}
82+
83+
// If all the heuristics fail, let's try to retrieve the view manager from the bridge/bridgeProxy
84+
if (bridge != nil) {
85+
return [[bridge moduleForName:RCTNSStringFromString(componentName)] class];
86+
}
87+
88+
if (bridgeProxy != nil) {
89+
return [[bridgeProxy moduleForName:RCTNSStringFromString(componentName) lazilyLoadIfNecessary:NO] class];
90+
}
91+
92+
return nil;
93+
}
94+
7795
static const std::shared_ptr<void> constructCoordinator(
7896
const ContextContainer::Shared &contextContainer,
7997
const ComponentDescriptor::Flavor &flavor)
8098
{
81-
auto componentName = *std::static_pointer_cast<std::string const>(flavor);
82-
Class viewManagerClass = getViewManagerFromComponentName(componentName);
83-
assert(viewManagerClass);
8499
auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
85100
RCTBridge *bridge;
86101
if (optionalBridge) {
@@ -92,6 +107,10 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
92107
if (optionalBridgeProxy) {
93108
bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
94109
}
110+
111+
auto componentName = *std::static_pointer_cast<std::string const>(flavor);
112+
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
113+
assert(viewManagerClass);
95114

96115
auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
97116
RCTEventDispatcher *eventDispatcher;

0 commit comments

Comments
 (0)