Skip to content

Commit 6534718

Browse files
d16rfacebook-github-bot
authored andcommitted
Fix LazilyLoadView lookup so that it can drop RCT prefixes.
Summary: 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
1 parent 1b4fd64 commit 6534718

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

React/Base/RCTBridge.m

+1-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,7 @@ void RCTRegisterModule(Class moduleClass)
8282
name = NSStringFromClass(cls);
8383
}
8484

85-
if ([name hasPrefix:@"RK"]) {
86-
name = [name substringFromIndex:2];
87-
} else if ([name hasPrefix:@"RCT"]) {
88-
name = [name substringFromIndex:3];
89-
}
90-
91-
return name;
85+
return RCTDropReactPrefixes(name);
9286
}
9387

9488
static BOOL jsiNativeModuleEnabled = NO;

React/Base/RCTUtils.h

+3
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,7 @@ RCT_EXTERN NSString *RCTUIKitLocalizedString(NSString *string);
146146
RCT_EXTERN NSString *__nullable RCTGetURLQueryParam(NSURL *__nullable URL, NSString *param);
147147
RCT_EXTERN NSURL *__nullable RCTURLByReplacingQueryParam(NSURL *__nullable URL, NSString *param, NSString *__nullable value);
148148

149+
// Given a string, drop common RN prefixes (RCT, RK, etc.)
150+
RCT_EXTERN NSString *RCTDropReactPrefixes(NSString *s);
151+
149152
NS_ASSUME_NONNULL_END

React/Base/RCTUtils.m

+11
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,14 @@ static void RCTGetRGBAColorComponents(CGColorRef color, CGFloat rgba[4])
900900
components.queryItems = queryItems;
901901
return components.URL;
902902
}
903+
904+
RCT_EXTERN NSString *RCTDropReactPrefixes(NSString *s)
905+
{
906+
if ([s hasPrefix:@"RK"]) {
907+
return [s substringFromIndex:2];
908+
} else if ([s hasPrefix:@"RCT"]) {
909+
return [s substringFromIndex:3];
910+
}
911+
912+
return s;
913+
}

React/Modules/RCTUIManager.m

+8
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,14 @@ static void RCTMeasureLayout(RCTShadowView *view,
15721572
}
15731573

15741574
id module = [self.bridge moduleForName:moduleName];
1575+
if (module == nil) {
1576+
// There is all sorts of code in this codebase that drops prefixes.
1577+
//
1578+
// If we didn't find a module, it's possible because it's stored under a key
1579+
// which had RCT Prefixes stripped. Lets check one more time...
1580+
module = [self.bridge moduleForName:RCTDropReactPrefixes(moduleName)];
1581+
}
1582+
15751583
RCTComponentData *componentData = [[RCTComponentData alloc] initWithManagerClass:[module class] bridge:self.bridge];
15761584
_componentDataByName[componentData.name] = componentData;
15771585
NSMutableDictionary *directEvents = [NSMutableDictionary new];

0 commit comments

Comments
 (0)