Skip to content

Commit

Permalink
Honor custom name when TM is registered with the legacy mode. (#38547)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38547

Before this change, when a turbomodule was registered using the `RCT_EXPORT_MODULE()` function using a custom name, the TM was not found in the registry.

With this change, we are adding a fallback that looks in the list of registered TM, asking for the name used by the user to register it.

This fallback is executed only if no other method was successful before as it is more expensive.

## CHANGELOG
[iOS][Fixed] - Honor the custom name choosen by the user to register the module.

Reviewed By: philIip

Differential Revision: D47666848

fbshipit-source-id: 545855de1c398726b9449a0d77af7f1756cca233
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jul 24, 2023
1 parent 4aa53d2 commit 16fe8da
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,25 @@ - (Class)_getModuleClassFromName:(const char *)moduleName
moduleClass = [_delegate getModuleClassFromName:moduleName];
}

if (!moduleClass) {
moduleClass = getFallbackClassFromName(moduleName);
if (moduleClass != nil) {
return moduleClass;
}

moduleClass = getFallbackClassFromName(moduleName);
if (moduleClass != nil) {
return moduleClass;
}

// fallback on modules registered throught RCT_EXPORT_MODULE with custom names
NSString *objcModuleName = [NSString stringWithUTF8String:moduleName];
NSArray<Class> *modules = RCTGetModuleClasses();
for (Class current in modules) {
NSString *currentModuleName = [current moduleName];
if ([objcModuleName isEqualToString:currentModuleName]) {
return current;
}
}

return moduleClass;
}

Expand Down

0 comments on commit 16fe8da

Please sign in to comment.