Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void RCTRegisterModule(Class moduleClass)
cls);
#endif

NSString *name = [cls moduleName];
NSString *name = [cls respondsToSelector:@selector(moduleName)] ? [cls moduleName] : nil;
if (name.length == 0) {
name = NSStringFromClass(cls);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/react-native/React/Base/RCTBridgeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ RCT_EXTERN_C_END

#endif // defined(RCT_REMOVE_LEGACY_MODULE_INTEROP) && defined(RCT_REMOVE_LEGACY_COMPONENT_INTEROP)

// Implemented by RCT_EXPORT_MODULE
+ (NSString *)moduleName;

@optional

// Implemented by RCT_EXPORT_MODULE. When absent, callers fall back to the ObjC class
// name, so a TurboModule resolved via a provider or plugin socket need not declare it.
+ (NSString *)moduleName;

/**
* A reference to the RCTModuleRegistry. Useful for modules that require access
* to other NativeModules. To implement this in your module, just add `@synthesize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ + (BOOL)isSupported:(NSString *)componentName

for (Class moduleClass in registeredModules) {
id<RCTBridgeModule> bridgeModule = (id<RCTBridgeModule>)moduleClass;
NSString *moduleName = [[bridgeModule moduleName] isEqualToString:@""]
NSString *exportedName = [bridgeModule respondsToSelector:@selector(moduleName)] ? [bridgeModule moduleName] : nil;
NSString *moduleName = exportedName.length == 0
? [NSStringFromClass(moduleClass) stringByReplacingOccurrencesOfString:@"Manager" withString:@""]
: [bridgeModule moduleName];
: exportedName;

if (supportedLegacyViewComponents[moduleName] == NULL) {
supportedLegacyViewComponents[moduleName] = moduleClass;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Views/RCTComponentData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>
// We want to get rid of RCT and RK prefixes, but a lot of JS code still references
// view names by prefix. So, while RCTBridgeModuleNameForClass now drops these
// prefixes by default, we'll still keep them around here.
NSString *name = [managerClass moduleName];
NSString *name = [managerClass respondsToSelector:@selector(moduleName)] ? [managerClass moduleName] : nil;
if (name.length == 0) {
name = NSStringFromClass(managerClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ - (Class)_getModuleClassFromName:(const char *)moduleName
NSString *objcModuleName = [NSString stringWithUTF8String:moduleName];
NSArray<Class> *modules = RCTGetModuleClasses();
for (Class current in modules) {
// A class without +moduleName has no custom JS name, so it can never match here.
if (![current respondsToSelector:@selector(moduleName)]) {
continue;
}
NSString *currentModuleName = [current moduleName];
if ([objcModuleName isEqualToString:currentModuleName]) {
return current;
Expand Down
Loading