Browse files

Fix LazilyLoadView lookup so that it can drop RCT prefixes.

While debugging internally, we have found that modules are almost always registered
with their "RK" or "RCT" prefixes dropped.

However, if a view is named `RCTFooView` and needs `RCTFooViewManager` to render natively, it will almost never find it because `RCT` was dropped from the key to the ViewManager instance.

In the event you look for a `ViewManager` and don't find it, this strips any "React" prefixes from your key and tries ones more time.

Reviewed By: spredolac

Differential Revision: D10734005

fbshipit-source-id: 2bfa6f19830f14f09af2fe7dc7e44b7e26e0ac3f
  • Loading branch information...
d16r authored and facebook-github-bot committed Oct 26, 2018
1 parent 1b4fd64 commit 6534718a1898aa472e255d2aa9a0a6cae305619a
Showing with 23 additions and 7 deletions.
  1. +1 −7 React/Base/RCTBridge.m
  2. +3 −0 React/Base/RCTUtils.h
  3. +11 −0 React/Base/RCTUtils.m
  4. +8 −0 React/Modules/RCTUIManager.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;
@@ -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);

@@ -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;
@@ -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;
NSMutableDictionary *directEvents = [NSMutableDictionary new];

0 comments on commit 6534718

Please sign in to comment.