Fabric: Using view name argument in `FabricUIManager.createNode()`

Summary: We are going to have not only <View> component soon!

Reviewed By: mdvacca

Differential Revision: D7738579

fbshipit-source-id: 5165762b98d94f74d40d016722be36a04d45f264
This commit is contained in:
Valentin Shergin 2018-04-26 17:51:39 -07:00 committed by Facebook Github Bot
parent 98b4747041
commit 3428808b97
1 changed files with 13 additions and 1 deletions

View File

@ -38,6 +38,16 @@ static const RawProps rawPropsFromDynamic(const folly::dynamic object) {
return result;
}
static const std::string componentNameByReactViewName(std::string viewName) {
std::string rctPrefix("RCT");
if (std::mismatch(rctPrefix.begin(), rctPrefix.end(), viewName.begin()).first == rctPrefix.end()) {
// If `viewName` has "RCT" prefix, remove it.
viewName.erase(0, 3);
}
return viewName;
}
FabricUIManager::FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry) {
componentDescriptorRegistry_ = componentDescriptorRegistry;
}
@ -52,7 +62,9 @@ UIManagerDelegate *FabricUIManager::getDelegate() {
SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int rootTag, folly::dynamic props, void *instanceHandle) {
LOG(INFO) << "FabricUIManager::createNode(tag: " << tag << ", name: " << viewName << ", rootTag" << rootTag << ", props: " << props << ")";
const SharedComponentDescriptor &componentDescriptor = (*componentDescriptorRegistry_)["View"];
ComponentName componentName = componentNameByReactViewName(viewName);
const SharedComponentDescriptor &componentDescriptor = (*componentDescriptorRegistry_)[componentName];
RawProps rawProps = rawPropsFromDynamic(props);
SharedShadowNode shadowNode =