Skip to content

Commit 1a39d86

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

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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:YES] 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) {
@@ -93,6 +108,10 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
93108
bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
94109
}
95110

111+
auto componentName = *std::static_pointer_cast<std::string const>(flavor);
112+
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
113+
assert(viewManagerClass);
114+
96115
auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
97116
RCTEventDispatcher *eventDispatcher;
98117
if (optionalEventDispatcher) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ - (void)setProps:(const folly::dynamic &)props forView:(UIView *)view
101101
if (props.isObject()) {
102102
NSDictionary<NSString *, id> *convertedProps = convertFollyDynamicToId(props);
103103
[_componentData setProps:convertedProps forView:view];
104+
105+
if ([view respondsToSelector:@selector(didSetProps:)]) {
106+
[view performSelector:@selector(didSetProps:) withObject:[convertedProps allKeys]];
107+
}
104108
}
105109
}
106110

0 commit comments

Comments
 (0)