mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor componentNameByReactViewName into separate file
Summary: Changelog: [internal] Extract componentNameByReactViewName to separate file so it can be used elsewhere. Reviewed By: shergin, mdvacca Differential Revision: D26946159 fbshipit-source-id: cf69df1f80f1c1938fc667f4666a5d3fec5a9658
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6d1a4d3864
commit
fdb2bb76ec
@@ -7,6 +7,8 @@
|
||||
|
||||
#include "ComponentDescriptorRegistry.h"
|
||||
|
||||
#include "componentNameByReactViewName.h"
|
||||
|
||||
#include <react/debug/react_native_assert.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
||||
#include <react/renderer/core/ShadowNodeFragment.h>
|
||||
@@ -50,64 +52,6 @@ void ComponentDescriptorRegistry::registerComponentDescriptor(
|
||||
_registryByName[componentName] = componentDescriptor;
|
||||
}
|
||||
|
||||
static std::string componentNameByReactViewName(std::string viewName) {
|
||||
// We need this function only for the transition period;
|
||||
// eventually, all names will be unified.
|
||||
|
||||
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, rctPrefix.length());
|
||||
}
|
||||
|
||||
// Fabric uses slightly new names for Text components because of differences
|
||||
// in semantic.
|
||||
if (viewName == "Text") {
|
||||
return "Paragraph";
|
||||
}
|
||||
|
||||
// TODO T63839307: remove this condition after deleting TextInlineImage from
|
||||
// non-Fabric code
|
||||
if (viewName == "TextInlineImage") {
|
||||
return "Image";
|
||||
}
|
||||
if (viewName == "VirtualText") {
|
||||
return "Text";
|
||||
}
|
||||
|
||||
if (viewName == "ImageView") {
|
||||
return "Image";
|
||||
}
|
||||
|
||||
if (viewName == "AndroidHorizontalScrollView") {
|
||||
return "ScrollView";
|
||||
}
|
||||
|
||||
if (viewName == "RKShimmeringView") {
|
||||
return "ShimmeringView";
|
||||
}
|
||||
|
||||
if (viewName == "RefreshControl") {
|
||||
return "PullToRefreshView";
|
||||
}
|
||||
|
||||
// We need this temporarily for testing purposes until we have proper
|
||||
// implementation of core components.
|
||||
// iOS-only
|
||||
if (viewName == "ScrollContentView") {
|
||||
return "View";
|
||||
}
|
||||
|
||||
// iOS-only
|
||||
if (viewName == "MultilineTextInputView" ||
|
||||
viewName == "SinglelineTextInputView") {
|
||||
return "TextInput";
|
||||
}
|
||||
|
||||
return viewName;
|
||||
}
|
||||
|
||||
ComponentDescriptor const &ComponentDescriptorRegistry::at(
|
||||
std::string const &componentName) const {
|
||||
std::shared_lock<better::shared_mutex> lock(mutex_);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "componentNameByReactViewName.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
std::string componentNameByReactViewName(std::string viewName) {
|
||||
// We need this function only for the transition period;
|
||||
// eventually, all names will be unified.
|
||||
|
||||
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, rctPrefix.length());
|
||||
}
|
||||
|
||||
// Fabric uses slightly new names for Text components because of differences
|
||||
// in semantic.
|
||||
if (viewName == "Text") {
|
||||
return "Paragraph";
|
||||
}
|
||||
|
||||
// TODO T63839307: remove this condition after deleting TextInlineImage from
|
||||
// non-Fabric code
|
||||
if (viewName == "TextInlineImage") {
|
||||
return "Image";
|
||||
}
|
||||
if (viewName == "VirtualText") {
|
||||
return "Text";
|
||||
}
|
||||
|
||||
if (viewName == "ImageView") {
|
||||
return "Image";
|
||||
}
|
||||
|
||||
if (viewName == "AndroidHorizontalScrollView") {
|
||||
return "ScrollView";
|
||||
}
|
||||
|
||||
if (viewName == "RKShimmeringView") {
|
||||
return "ShimmeringView";
|
||||
}
|
||||
|
||||
if (viewName == "RefreshControl") {
|
||||
return "PullToRefreshView";
|
||||
}
|
||||
|
||||
// We need this temporarily for testing purposes until we have proper
|
||||
// implementation of core components.
|
||||
// iOS-only
|
||||
if (viewName == "ScrollContentView") {
|
||||
return "View";
|
||||
}
|
||||
|
||||
// iOS-only
|
||||
if (viewName == "MultilineTextInputView" ||
|
||||
viewName == "SinglelineTextInputView") {
|
||||
return "TextInput";
|
||||
}
|
||||
|
||||
return viewName;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/**
|
||||
* Provides mapping from old view name format to the new format.
|
||||
*/
|
||||
std::string componentNameByReactViewName(std::string viewName);
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user