Skip to content

Commit fdb2bb7

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
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
1 parent 6d1a4d3 commit fdb2bb7

File tree

3 files changed

+95
-58
lines changed

3 files changed

+95
-58
lines changed

ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "ComponentDescriptorRegistry.h"
99

10+
#include "componentNameByReactViewName.h"
11+
1012
#include <react/debug/react_native_assert.h>
1113
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
1214
#include <react/renderer/core/ShadowNodeFragment.h>
@@ -50,64 +52,6 @@ void ComponentDescriptorRegistry::registerComponentDescriptor(
5052
_registryByName[componentName] = componentDescriptor;
5153
}
5254

53-
static std::string componentNameByReactViewName(std::string viewName) {
54-
// We need this function only for the transition period;
55-
// eventually, all names will be unified.
56-
57-
std::string rctPrefix("RCT");
58-
if (std::mismatch(rctPrefix.begin(), rctPrefix.end(), viewName.begin())
59-
.first == rctPrefix.end()) {
60-
// If `viewName` has "RCT" prefix, remove it.
61-
viewName.erase(0, rctPrefix.length());
62-
}
63-
64-
// Fabric uses slightly new names for Text components because of differences
65-
// in semantic.
66-
if (viewName == "Text") {
67-
return "Paragraph";
68-
}
69-
70-
// TODO T63839307: remove this condition after deleting TextInlineImage from
71-
// non-Fabric code
72-
if (viewName == "TextInlineImage") {
73-
return "Image";
74-
}
75-
if (viewName == "VirtualText") {
76-
return "Text";
77-
}
78-
79-
if (viewName == "ImageView") {
80-
return "Image";
81-
}
82-
83-
if (viewName == "AndroidHorizontalScrollView") {
84-
return "ScrollView";
85-
}
86-
87-
if (viewName == "RKShimmeringView") {
88-
return "ShimmeringView";
89-
}
90-
91-
if (viewName == "RefreshControl") {
92-
return "PullToRefreshView";
93-
}
94-
95-
// We need this temporarily for testing purposes until we have proper
96-
// implementation of core components.
97-
// iOS-only
98-
if (viewName == "ScrollContentView") {
99-
return "View";
100-
}
101-
102-
// iOS-only
103-
if (viewName == "MultilineTextInputView" ||
104-
viewName == "SinglelineTextInputView") {
105-
return "TextInput";
106-
}
107-
108-
return viewName;
109-
}
110-
11155
ComponentDescriptor const &ComponentDescriptorRegistry::at(
11256
std::string const &componentName) const {
11357
std::shared_lock<better::shared_mutex> lock(mutex_);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "componentNameByReactViewName.h"
9+
10+
namespace facebook {
11+
namespace react {
12+
13+
std::string componentNameByReactViewName(std::string viewName) {
14+
// We need this function only for the transition period;
15+
// eventually, all names will be unified.
16+
17+
std::string rctPrefix("RCT");
18+
if (std::mismatch(rctPrefix.begin(), rctPrefix.end(), viewName.begin())
19+
.first == rctPrefix.end()) {
20+
// If `viewName` has "RCT" prefix, remove it.
21+
viewName.erase(0, rctPrefix.length());
22+
}
23+
24+
// Fabric uses slightly new names for Text components because of differences
25+
// in semantic.
26+
if (viewName == "Text") {
27+
return "Paragraph";
28+
}
29+
30+
// TODO T63839307: remove this condition after deleting TextInlineImage from
31+
// non-Fabric code
32+
if (viewName == "TextInlineImage") {
33+
return "Image";
34+
}
35+
if (viewName == "VirtualText") {
36+
return "Text";
37+
}
38+
39+
if (viewName == "ImageView") {
40+
return "Image";
41+
}
42+
43+
if (viewName == "AndroidHorizontalScrollView") {
44+
return "ScrollView";
45+
}
46+
47+
if (viewName == "RKShimmeringView") {
48+
return "ShimmeringView";
49+
}
50+
51+
if (viewName == "RefreshControl") {
52+
return "PullToRefreshView";
53+
}
54+
55+
// We need this temporarily for testing purposes until we have proper
56+
// implementation of core components.
57+
// iOS-only
58+
if (viewName == "ScrollContentView") {
59+
return "View";
60+
}
61+
62+
// iOS-only
63+
if (viewName == "MultilineTextInputView" ||
64+
viewName == "SinglelineTextInputView") {
65+
return "TextInput";
66+
}
67+
68+
return viewName;
69+
}
70+
71+
} // namespace react
72+
} // namespace facebook
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <string>
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
/**
16+
* Provides mapping from old view name format to the new format.
17+
*/
18+
std::string componentNameByReactViewName(std::string viewName);
19+
20+
} // namespace react
21+
} // namespace facebook

0 commit comments

Comments
 (0)