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
This commit is contained in:
Samuel Susla 2021-08-28 06:58:06 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 1bc885b8b8
Коммит 7dc22116b0
3 изменённых файлов: 21 добавлений и 56 удалений

Просмотреть файл

@ -1093,13 +1093,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
getComponentDescriptorForShadowView(baselineShadowView)
.cloneProps(propsParserContext, viewStart.props, {});
// Dynamic cast, because - we don't know the type of this
// ShadowNode, it could be Image or Text or something else with
// different base props.
const auto viewProps =
dynamic_cast<const ViewProps *>(props.get());
if (viewProps != nullptr) {
const_cast<ViewProps *>(viewProps)->opacity = 0;
if (baselineShadowView.traits.check(
ShadowNodeTraits::Trait::ViewKind)) {
auto const &viewProps =
*std::static_pointer_cast<ViewProps const>(props);
const_cast<ViewProps &>(viewProps).opacity = 0;
}
react_native_assert(props != nullptr);
@ -1118,13 +1116,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
getComponentDescriptorForShadowView(baselineShadowView)
.cloneProps(propsParserContext, viewStart.props, {});
// Dynamic cast, because - we don't know the type of this
// ShadowNode, it could be Image or Text or something else with
// different base props.
const auto viewProps =
dynamic_cast<const ViewProps *>(props.get());
if (viewProps != nullptr) {
const_cast<ViewProps *>(viewProps)->transform =
if (baselineShadowView.traits.check(
ShadowNodeTraits::Trait::ViewKind)) {
auto const &viewProps =
*std::static_pointer_cast<ViewProps const>(props);
const_cast<ViewProps &>(viewProps).transform =
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
}
@ -1221,13 +1217,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
getComponentDescriptorForShadowView(baselineShadowView)
.cloneProps(propsParserContext, viewFinal.props, {});
// Dynamic cast, because - we don't know the type of this
// ShadowNode, it could be Image or Text or something else with
// different base props.
const auto viewProps =
dynamic_cast<const ViewProps *>(props.get());
if (viewProps != nullptr) {
const_cast<ViewProps *>(viewProps)->opacity = 0;
if (baselineShadowView.traits.check(
ShadowNodeTraits::Trait::ViewKind)) {
auto const &viewProps =
*std::static_pointer_cast<ViewProps const>(props);
const_cast<ViewProps &>(viewProps).opacity = 0;
}
react_native_assert(props != nullptr);
@ -1248,13 +1242,11 @@ LayoutAnimationKeyFrameManager::pullTransaction(
getComponentDescriptorForShadowView(baselineShadowView)
.cloneProps(propsParserContext, viewFinal.props, {});
// Dynamic cast, because - we don't know the type of this
// ShadowNode, it could be Image or Text or something else with
// different base props.
const auto viewProps =
dynamic_cast<const ViewProps *>(props.get());
if (viewProps != nullptr) {
const_cast<ViewProps *>(viewProps)->transform =
if (baselineShadowView.traits.check(
ShadowNodeTraits::Trait::ViewKind)) {
auto const &viewProps =
*std::static_pointer_cast<ViewProps const>(props);
const_cast<ViewProps &>(viewProps).transform =
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
}

Просмотреть файл

@ -24,7 +24,7 @@ class ViewShadowNode final : public ConcreteViewShadowNode<
ViewEventEmitter> {
public:
static ShadowNodeTraits BaseTraits() {
auto traits = BaseShadowNode::BaseTraits();
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::View);
return traits;
}

Просмотреть файл

@ -45,10 +45,6 @@ class ContextContainer final {
std::unique_lock<better::shared_mutex> lock(mutex_);
instances_.insert({key, std::make_shared<T>(instance)});
#ifdef REACT_NATIVE_DEBUG
typeNames_.insert({key, typeid(T).name()});
#endif
}
/*
@ -59,10 +55,6 @@ class ContextContainer final {
std::unique_lock<better::shared_mutex> lock(mutex_);
instances_.erase(key);
#ifdef REACT_NATIVE_DEBUG
typeNames_.erase(key);
#endif
}
/*
@ -76,11 +68,6 @@ class ContextContainer final {
for (auto const &pair : contextContainer.instances_) {
instances_.erase(pair.first);
instances_.insert(pair);
#ifdef REACT_NATIVE_DEBUG
typeNames_.erase(pair.first);
typeNames_.insert(
{pair.first, contextContainer.typeNames_.at(pair.first)});
#endif
}
}
@ -96,11 +83,6 @@ class ContextContainer final {
react_native_assert(
instances_.find(key) != instances_.end() &&
"ContextContainer doesn't have an instance for given key.");
#ifdef REACT_NATIVE_DEBUG
react_native_assert(
typeNames_.at(key) == typeid(T).name() &&
"ContextContainer stores an instance of different type for given key.");
#endif
return *std::static_pointer_cast<T>(instances_.at(key));
}
@ -118,12 +100,6 @@ class ContextContainer final {
return {};
}
#ifdef REACT_NATIVE_DEBUG
react_native_assert(
typeNames_.at(key) == typeid(T).name() &&
"ContextContainer stores an instance of different type for given key.");
#endif
return *std::static_pointer_cast<T>(iterator->second);
}
@ -131,9 +107,6 @@ class ContextContainer final {
mutable better::shared_mutex mutex_;
// Protected by mutex_`.
mutable better::map<std::string, std::shared_ptr<void>> instances_;
#ifdef REACT_NATIVE_DEBUG
mutable better::map<std::string, std::string> typeNames_;
#endif
};
} // namespace react