Skip to content

Commit 7dc2211

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Remove RTTI from LayoutAnimations
Summary: changelog: [internal] Remote use of dynamic_cast from LayoutAnimations. Reviewed By: JoshuaGross, cortinico Differential Revision: D30602864 fbshipit-source-id: ce23f9b4a8b4e28d17d2297d64d8e460a1e03472
1 parent 1bc885b commit 7dc2211

File tree

3 files changed

+21
-56
lines changed

3 files changed

+21
-56
lines changed

ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,13 +1093,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
10931093
getComponentDescriptorForShadowView(baselineShadowView)
10941094
.cloneProps(propsParserContext, viewStart.props, {});
10951095

1096-
// Dynamic cast, because - we don't know the type of this
1097-
// ShadowNode, it could be Image or Text or something else with
1098-
// different base props.
1099-
const auto viewProps =
1100-
dynamic_cast<const ViewProps *>(props.get());
1101-
if (viewProps != nullptr) {
1102-
const_cast<ViewProps *>(viewProps)->opacity = 0;
1096+
if (baselineShadowView.traits.check(
1097+
ShadowNodeTraits::Trait::ViewKind)) {
1098+
auto const &viewProps =
1099+
*std::static_pointer_cast<ViewProps const>(props);
1100+
const_cast<ViewProps &>(viewProps).opacity = 0;
11031101
}
11041102

11051103
react_native_assert(props != nullptr);
@@ -1118,13 +1116,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
11181116
getComponentDescriptorForShadowView(baselineShadowView)
11191117
.cloneProps(propsParserContext, viewStart.props, {});
11201118

1121-
// Dynamic cast, because - we don't know the type of this
1122-
// ShadowNode, it could be Image or Text or something else with
1123-
// different base props.
1124-
const auto viewProps =
1125-
dynamic_cast<const ViewProps *>(props.get());
1126-
if (viewProps != nullptr) {
1127-
const_cast<ViewProps *>(viewProps)->transform =
1119+
if (baselineShadowView.traits.check(
1120+
ShadowNodeTraits::Trait::ViewKind)) {
1121+
auto const &viewProps =
1122+
*std::static_pointer_cast<ViewProps const>(props);
1123+
const_cast<ViewProps &>(viewProps).transform =
11281124
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
11291125
}
11301126

@@ -1221,13 +1217,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
12211217
getComponentDescriptorForShadowView(baselineShadowView)
12221218
.cloneProps(propsParserContext, viewFinal.props, {});
12231219

1224-
// Dynamic cast, because - we don't know the type of this
1225-
// ShadowNode, it could be Image or Text or something else with
1226-
// different base props.
1227-
const auto viewProps =
1228-
dynamic_cast<const ViewProps *>(props.get());
1229-
if (viewProps != nullptr) {
1230-
const_cast<ViewProps *>(viewProps)->opacity = 0;
1220+
if (baselineShadowView.traits.check(
1221+
ShadowNodeTraits::Trait::ViewKind)) {
1222+
auto const &viewProps =
1223+
*std::static_pointer_cast<ViewProps const>(props);
1224+
const_cast<ViewProps &>(viewProps).opacity = 0;
12311225
}
12321226

12331227
react_native_assert(props != nullptr);
@@ -1248,13 +1242,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
12481242
getComponentDescriptorForShadowView(baselineShadowView)
12491243
.cloneProps(propsParserContext, viewFinal.props, {});
12501244

1251-
// Dynamic cast, because - we don't know the type of this
1252-
// ShadowNode, it could be Image or Text or something else with
1253-
// different base props.
1254-
const auto viewProps =
1255-
dynamic_cast<const ViewProps *>(props.get());
1256-
if (viewProps != nullptr) {
1257-
const_cast<ViewProps *>(viewProps)->transform =
1245+
if (baselineShadowView.traits.check(
1246+
ShadowNodeTraits::Trait::ViewKind)) {
1247+
auto const &viewProps =
1248+
*std::static_pointer_cast<ViewProps const>(props);
1249+
const_cast<ViewProps &>(viewProps).transform =
12581250
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
12591251
}
12601252

ReactCommon/react/renderer/components/view/ViewShadowNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ViewShadowNode final : public ConcreteViewShadowNode<
2424
ViewEventEmitter> {
2525
public:
2626
static ShadowNodeTraits BaseTraits() {
27-
auto traits = BaseShadowNode::BaseTraits();
27+
auto traits = ConcreteViewShadowNode::BaseTraits();
2828
traits.set(ShadowNodeTraits::Trait::View);
2929
return traits;
3030
}

ReactCommon/react/utils/ContextContainer.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class ContextContainer final {
4545
std::unique_lock<better::shared_mutex> lock(mutex_);
4646

4747
instances_.insert({key, std::make_shared<T>(instance)});
48-
49-
#ifdef REACT_NATIVE_DEBUG
50-
typeNames_.insert({key, typeid(T).name()});
51-
#endif
5248
}
5349

5450
/*
@@ -59,10 +55,6 @@ class ContextContainer final {
5955
std::unique_lock<better::shared_mutex> lock(mutex_);
6056

6157
instances_.erase(key);
62-
63-
#ifdef REACT_NATIVE_DEBUG
64-
typeNames_.erase(key);
65-
#endif
6658
}
6759

6860
/*
@@ -76,11 +68,6 @@ class ContextContainer final {
7668
for (auto const &pair : contextContainer.instances_) {
7769
instances_.erase(pair.first);
7870
instances_.insert(pair);
79-
#ifdef REACT_NATIVE_DEBUG
80-
typeNames_.erase(pair.first);
81-
typeNames_.insert(
82-
{pair.first, contextContainer.typeNames_.at(pair.first)});
83-
#endif
8471
}
8572
}
8673

@@ -96,11 +83,6 @@ class ContextContainer final {
9683
react_native_assert(
9784
instances_.find(key) != instances_.end() &&
9885
"ContextContainer doesn't have an instance for given key.");
99-
#ifdef REACT_NATIVE_DEBUG
100-
react_native_assert(
101-
typeNames_.at(key) == typeid(T).name() &&
102-
"ContextContainer stores an instance of different type for given key.");
103-
#endif
10486
return *std::static_pointer_cast<T>(instances_.at(key));
10587
}
10688

@@ -118,22 +100,13 @@ class ContextContainer final {
118100
return {};
119101
}
120102

121-
#ifdef REACT_NATIVE_DEBUG
122-
react_native_assert(
123-
typeNames_.at(key) == typeid(T).name() &&
124-
"ContextContainer stores an instance of different type for given key.");
125-
#endif
126-
127103
return *std::static_pointer_cast<T>(iterator->second);
128104
}
129105

130106
private:
131107
mutable better::shared_mutex mutex_;
132108
// Protected by mutex_`.
133109
mutable better::map<std::string, std::shared_ptr<void>> instances_;
134-
#ifdef REACT_NATIVE_DEBUG
135-
mutable better::map<std::string, std::string> typeNames_;
136-
#endif
137110
};
138111

139112
} // namespace react

0 commit comments

Comments
 (0)