diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 5171f2ae220fd7..2a0e0402664c95 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -82,13 +82,7 @@ void RCTRegisterModule(Class moduleClass) name = NSStringFromClass(cls); } - if ([name hasPrefix:@"RK"]) { - name = [name substringFromIndex:2]; - } else if ([name hasPrefix:@"RCT"]) { - name = [name substringFromIndex:3]; - } - - return name; + return RCTDropReactPrefixes(name); } static BOOL jsiNativeModuleEnabled = NO; diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index f55ef47430ed8d..ac47ef099c9fa4 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -146,4 +146,7 @@ RCT_EXTERN NSString *RCTUIKitLocalizedString(NSString *string); RCT_EXTERN NSString *__nullable RCTGetURLQueryParam(NSURL *__nullable URL, NSString *param); RCT_EXTERN NSURL *__nullable RCTURLByReplacingQueryParam(NSURL *__nullable URL, NSString *param, NSString *__nullable value); +// Given a string, drop common RN prefixes (RCT, RK, etc.) +RCT_EXTERN NSString *RCTDropReactPrefixes(NSString *s); + NS_ASSUME_NONNULL_END diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 7c59b947555865..13067cc544a439 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -900,3 +900,14 @@ static void RCTGetRGBAColorComponents(CGColorRef color, CGFloat rgba[4]) components.queryItems = queryItems; return components.URL; } + +RCT_EXTERN NSString *RCTDropReactPrefixes(NSString *s) +{ + if ([s hasPrefix:@"RK"]) { + return [s substringFromIndex:2]; + } else if ([s hasPrefix:@"RCT"]) { + return [s substringFromIndex:3]; + } + + return s; +} diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 9429f135d4eae7..e1b5dbc7db267b 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1572,6 +1572,14 @@ static void RCTMeasureLayout(RCTShadowView *view, } id module = [self.bridge moduleForName:moduleName]; + if (module == nil) { + // There is all sorts of code in this codebase that drops prefixes. + // + // If we didn't find a module, it's possible because it's stored under a key + // which had RCT Prefixes stripped. Lets check one more time... + module = [self.bridge moduleForName:RCTDropReactPrefixes(moduleName)]; + } + RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:[module class] bridge:self.bridge]; _componentDataByName[componentData.name] = componentData; NSMutableDictionary *directEvents = [NSMutableDictionary new];