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
This commit is contained in:
parent
1b4fd64325
commit
6534718a18
|
@ -82,13 +82,7 @@ NSString *RCTBridgeModuleNameForClass(Class cls)
|
|||
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);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -900,3 +900,14 @@ NSURL *__nullable RCTURLByReplacingQueryParam(NSURL *__nullable URL, NSString *p
|
|||
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 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(lazilyLoadView:(NSString *)name)
|
|||
}
|
||||
|
||||
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];
|
||||
|
|
Loading…
Reference in New Issue