Skip to content

Commit daedbe6

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Make the interop-layer work with components with custom name (facebook#41207)
Summary: This should fix facebook#37905 (comment) When working on react-native-fast-image, we realized that the interop layer does not work for components where the exported name is different from the iOS class. To fix this, we can use the Bridge to retrieve the actual view manager, given the component name. This solution should be much more robust than making assumptions on the ViewManager name, given the ComponentName. On top of that, we realized tha the interop layer was not calling `didSetProps` after setting the props, so we are invoking that. bypass-github-export-checks ## Changelog: [iOS][Fixed] - Add support for Components with custom names in the interop layer. Pull Request resolved: facebook#41207 Test Plan: Tested locally on an app created in 0.72 and 0.73 in Bridge and Bridgeless mode. Reviewed By: cortinico Differential Revision: D50698172 Pulled By: cipolleschi fbshipit-source-id: 49aee905418515b0204febbbe6a67c0114f37029
1 parent 4eed12b commit daedbe6

File tree

3 files changed

+75
-50
lines changed

3 files changed

+75
-50
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,29 @@ 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+
{
79+
Class viewManager = getViewManagerFromComponentName(componentName);
80+
if (viewManager != nil) {
81+
return viewManager;
82+
}
83+
84+
// If all the heuristics fail, let's try to retrieve the view manager from the bridge/bridgeProxy
85+
if (bridge != nil) {
86+
return [[bridge moduleForName:RCTNSStringFromString(componentName)] class];
87+
}
88+
89+
if (bridgeProxy != nil) {
90+
return [[bridgeProxy moduleForName:RCTNSStringFromString(componentName) lazilyLoadIfNecessary:YES] class];
91+
}
92+
93+
return nil;
94+
}
95+
7796
static const std::shared_ptr<void> constructCoordinator(
7897
const ContextContainer::Shared &contextContainer,
7998
const ComponentDescriptor::Flavor &flavor)
8099
{
81-
auto componentName = *std::static_pointer_cast<std::string const>(flavor);
82-
Class viewManagerClass = getViewManagerFromComponentName(componentName);
83-
assert(viewManagerClass);
84100
auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
85101
RCTBridge *bridge;
86102
if (optionalBridge) {
@@ -93,6 +109,10 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
93109
bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
94110
}
95111

112+
auto componentName = *std::static_pointer_cast<std::string const>(flavor);
113+
Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
114+
assert(viewManagerClass);
115+
96116
auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
97117
RCTEventDispatcher *eventDispatcher;
98118
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

packages/rn-tester/Podfile.lock

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ PODS:
10241024
- hermes-engine
10251025
- RCT-Folly (= 2023.08.07.00)
10261026
- React-callinvoker
1027+
- React-cxxreact
10271028
- React-debug
10281029
- React-jsi
10291030
- React-rendererdebug
@@ -1249,60 +1250,60 @@ EXTERNAL SOURCES:
12491250
SPEC CHECKSUMS:
12501251
boost: 26fad476bfa736552bbfa698a06cc530475c1505
12511252
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
1252-
FBLazyVector: 43f93051832e03bd2862aa5705a8d6286d489c7b
1253-
FBReactNativeSpec: 435e3f74da6e06596f2f3eb2ef154c348c1fa4c5
1253+
FBLazyVector: a9d04c15a139b6d2b411dc48c14d0e5ccedb4dfc
1254+
FBReactNativeSpec: 2a0c0cdd738003bf9f6b8ee678e55f5a40ae555b
12541255
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
12551256
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
1256-
hermes-engine: 5b957e2b1bc248ee52eaaffbd39056cd49cbedfa
1257+
hermes-engine: 9860d876ccc006c2922d12ee7e991a449fad22e1
12571258
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
12581259
OCMock: 9491e4bec59e0b267d52a9184ff5605995e74be8
1259-
RCT-Folly: 3edb9330ce752fe48b85e6c8a65506033f95f4b9
1260-
RCTRequired: 50d04f276bb3293f8db92e39c7d47d5beb0beb0b
1261-
RCTTypeSafety: 0918b2a09cacf134da18081e75025aa450212e30
1262-
React: 82837b785c087ae2627ef81a8b17167fcde35640
1263-
React-callinvoker: 9c27ed29c8d60a13d37878ff7bdc575e973335a1
1260+
RCT-Folly: 823c6f6ec910a75d4ad28898b4a11cdee140b92a
1261+
RCTRequired: 7e59b7b76964f56c833d25dc6181f9369bd9f5b6
1262+
RCTTypeSafety: ef263f583381d5a3d5c7c8543665b59f60b33351
1263+
React: bd73f4f27cd1d73499cfbeed09619ce705b1bc6a
1264+
React-callinvoker: 33f9673aeeecc522f082896dc8c2d4440f2523bf
12641265
React-Codegen: 05b37234a5252f99c890f3e2544b278827b613ca
1265-
React-Core: 016adad37b605893752aa5ad434cc550aeed1b66
1266-
React-CoreModules: a9b7f506cfbed21ca2b1badcb060ad5428a8a67e
1267-
React-cxxreact: 6dc2309e559e2f1a0ad6dd91e8bbd7dc222b4a4c
1268-
React-debug: 52a9b1b03f6ca4b6bee1d983f278d2572e288c23
1269-
React-Fabric: c0d8b9fce1ed4a13eb952f812ec32dbe52b9b50f
1270-
React-FabricImage: 7e3d8b3f312b15d6e03aa02f2b9118ea67b28a92
1271-
React-graphics: 73aa28d1a6a7da9f1d1ebe9767a77eedf9c7ca63
1272-
React-hermes: 8cc7d97d9ab6d757caeefc035e20c70197fd7532
1273-
React-ImageManager: a1eb4d34a21188558f78ae4b8f069c428a32daa3
1274-
React-jserrorhandler: 9474d59b020e709ca2354023b09384ba7f6bbb82
1275-
React-jsi: 71027d70650d2c3611071ad90a4a51072b8e1aee
1276-
React-jsiexecutor: aeeff4184e288dec6cf0f0c7c6e284bef7035937
1277-
React-jsinspector: 307cf99c99fb2412b8462584750e3056203779b5
1278-
React-logger: 2ce299f7ba886013bc7d89e0fadc0fe9e5b44bde
1279-
React-Mapbuffer: 1ee84f85e8c02f2ff29035d6b21385db59d1d531
1280-
React-nativeconfig: 5e6e122ce27878bcf6a35a4370099d07db1e2238
1281-
React-NativeModulesApple: 25945f2f3e4df06bfeb2f7eb207ee3b218aa6932
1282-
React-perflogger: e2df5a18ce247143195df118612140cad5dd76b6
1283-
React-RCTActionSheet: 22226e928d8a400604bac1ad451683acd8a7cf27
1284-
React-RCTAnimation: 161de0ea5b66c215ad7f650d3f7c486c99627e16
1285-
React-RCTAppDelegate: 2f6243fc35be00835ea3a3ec5552ed18a138eb4e
1286-
React-RCTBlob: d3f90507c9cba09c806e4f7b89ee24468c26eaf3
1287-
React-RCTFabric: 71e066fb8e63c1d266bb412cbe6140b715f126e6
1288-
React-RCTImage: 481bfb64008e19d6185349a4f37a835d7ead028c
1289-
React-RCTLinking: 23b103a68352a995dd4d53868448e971f1da3c74
1290-
React-RCTNetwork: 0635c6a6f8802485840907e962979a4d781dd893
1291-
React-RCTPushNotification: 2ade6aaecce3c52d398de3e3bd913a5902c56644
1292-
React-RCTSettings: 5e780bd1ba78aa9e8ff4fd03854291c5278cb7b7
1293-
React-RCTTest: 02963cac7849d568858d1c149096c4865c0f39d6
1294-
React-RCTText: fc1d9e3c8256314e660146f513fca689c8b62f66
1295-
React-RCTVibration: 18fd0f93e1f80a1bf3683143a6d8e60537a57a8f
1296-
React-rendererdebug: 9561f232529d90da4f7fc22fb1527ba74c424625
1297-
React-rncore: 23af9b8bee03cb76801c6a901f93ed15e6a98ae9
1298-
React-runtimeexecutor: 90c1a545cec8636bff59d99ff4f9790c66fb91ca
1299-
React-runtimescheduler: c461f9023469e82a9805d58f5d7529e5b680d863
1300-
React-utils: e12647a82af88461f68c0623908d3ecf92873bb9
1301-
ReactCommon: b5e00c5199a10583ec367b38e964df27f88b1521
1302-
ReactCommon-Samples: 23ae71c0c1c3eaed67da997be3742c6feb7f9b9c
1266+
React-Core: 681613ba23a3e002b5daaac841179c1c8c09bf7d
1267+
React-CoreModules: 8a302a639ada9384da0b3b48f5efcef1581d97ff
1268+
React-cxxreact: 2270d9c87e6e903e308d2ca1b23ef3d43d9b709b
1269+
React-debug: 157114273ac8eaf71d4f7c5ceab02aa9c523fe8c
1270+
React-Fabric: 2dcdb072a58b84165cd311c33dbce7ea41a41df8
1271+
React-FabricImage: a9c2ae62757cc7f635a06d617febcbe248d68b75
1272+
React-graphics: c226a7bed2a3868552c26c792d916ec87da4b0a3
1273+
React-hermes: 114ebd73b7f528f10ee02c98acd1f8676396c84e
1274+
React-ImageManager: 5ee42fd7b963f214d3887babfa697cd3d364d35b
1275+
React-jserrorhandler: 9ec2310ccd65078a6a9aaa3126c42663990fccf9
1276+
React-jsi: 47b821f7f0d784644c315678c97682bcc023cc39
1277+
React-jsiexecutor: f39aa2f98a7057746933e06ddb1653c081047b04
1278+
React-jsinspector: ec2fb8cbc0b450bc3056108f1d37dc90495338c2
1279+
React-logger: 4b29f8a4c245d1639eb0bb42a20ea16b25cc0477
1280+
React-Mapbuffer: e5301f57f61bd9eeadb57944f7a12eba30021f80
1281+
React-nativeconfig: 05b0897cb72060b557126797400cc984b2568b0c
1282+
React-NativeModulesApple: 2d71dc507f4173ea772c8104689c6d71a913a28f
1283+
React-perflogger: 1ad14aec6ac9deea631579548b3a932bee2552fd
1284+
React-RCTActionSheet: e69af310a07e5b5f85257904b9d1d4ec214045ea
1285+
React-RCTAnimation: a92337f23c75e31a0d577756993ab8a258968673
1286+
React-RCTAppDelegate: 42d2f48edc44bd942d4cb28edce3d0144bf4caff
1287+
React-RCTBlob: f70f38a26b9b8bb25ae5d1fa3d09e7f610cc8c0e
1288+
React-RCTFabric: 5ca56c798eedcf81095a88dbb0fd73085272fa21
1289+
React-RCTImage: 0eda14109067cf83800f5cc75a3e1d19c9a5d3f6
1290+
React-RCTLinking: 4dc8fecb19f6d045895910ff184e97efb442185d
1291+
React-RCTNetwork: fe389d36f4ecdb4d3631e4bc2b7a764d57a41fe2
1292+
React-RCTPushNotification: 8b64e7c11de8f7ea856eb050a2717fc77973f7ee
1293+
React-RCTSettings: d351c2fa0a842ec55e693f8a3360f17194036176
1294+
React-RCTTest: 2fc0f3286497c787f14093b8fdc5b73c0450c2a1
1295+
React-RCTText: ca92b6f0facc595134508078917225c3ce0af048
1296+
React-RCTVibration: fa6b996ceeb6aed49c178c9f76259c7195e51269
1297+
React-rendererdebug: 70cc63ede660873a2ea1ab1758e738ef7066a49e
1298+
React-rncore: a1c8004539fb9e41fb6f1d435934e79a1d40fbfb
1299+
React-runtimeexecutor: c6e0cda0af0b538eab168710de14b1828d3ccfce
1300+
React-runtimescheduler: 98e48cb5fd93c19f09ef808a0a65d4cd91c9484c
1301+
React-utils: b239995f8239878dd11f4889bf29b5b1025c66a9
1302+
ReactCommon: bff346950afee877611875f731c17e20a961c12c
1303+
ReactCommon-Samples: edf5dabd6ce5654d08665c4ef7fef85072b89e74
13031304
ScreenshotManager: 2b23b74d25f5e307f7b4d21173a61a3934e69475
13041305
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1305-
Yoga: fb79f7ef3685dd4f620174459e29bd575334cde3
1306+
Yoga: e8db4558087ce4980a67ce621aa91acc9dbe88fc
13061307

13071308
PODFILE CHECKSUM: c0120ff99aea9c7141bc22179e0f6be99c81a601
13081309

0 commit comments

Comments
 (0)