From 3428808b97bf8390d802d7863295d8625fbda64a Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 26 Apr 2018 17:51:39 -0700 Subject: [PATCH] Fabric: Using view name argument in `FabricUIManager.createNode()` Summary: We are going to have not only component soon! Reviewed By: mdvacca Differential Revision: D7738579 fbshipit-source-id: 5165762b98d94f74d40d016722be36a04d45f264 --- ReactCommon/fabric/uimanager/FabricUIManager.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 20207328312..dc73808f4c3 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -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 =