mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51588 changelog: [internal] AnimatedNode never outlive NativeAnimatedNodesManager. We can safely use raw pointer here instead of shared_ptr. This improves a C++ binary size a little bit. Reviewed By: rshest Differential Revision: D75148487 fbshipit-source-id: 4c2f6dc6e4de670be37dd3b65dc3a8d63d546150
71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
/*
|
|
* Adapted from react-native-windows under the MIT license.
|
|
*/
|
|
|
|
#include "AnimatedNode.h"
|
|
#include <react/renderer/animated/NativeAnimatedNodesManager.h>
|
|
|
|
#include <utility>
|
|
|
|
namespace facebook::react {
|
|
|
|
AnimatedNode::AnimatedNode(
|
|
Tag tag,
|
|
folly::dynamic config,
|
|
NativeAnimatedNodesManager& manager,
|
|
AnimatedNodeType type)
|
|
: tag_(tag), manager_(&manager), type_(type), config_(std::move(config)) {}
|
|
|
|
void AnimatedNode::addChild(const Tag animatedNodeTag) {
|
|
children_.insert(animatedNodeTag);
|
|
getChildNode(animatedNodeTag)->onAttachToNode(tag_);
|
|
}
|
|
|
|
void AnimatedNode::removeChild(const Tag tag) {
|
|
if (const auto childNode = getChildNode(tag)) {
|
|
childNode->onDetachedFromNode(tag_);
|
|
children_.erase(tag);
|
|
}
|
|
}
|
|
|
|
AnimatedNode* AnimatedNode::getChildNode(Tag tag) {
|
|
if (children_.find(tag) != children_.end()) {
|
|
return manager_->getAnimatedNode<AnimatedNode>(tag);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
std::optional<AnimatedNodeType> AnimatedNode::getNodeTypeByName(
|
|
const std::string& nodeTypeName) {
|
|
static std::unordered_map<std::string, AnimatedNodeType> typeNames = {
|
|
{"style", AnimatedNodeType::Style},
|
|
{"value", AnimatedNodeType::Value},
|
|
{"color", AnimatedNodeType::Color},
|
|
{"props", AnimatedNodeType::Props},
|
|
{"interpolation", AnimatedNodeType::Interpolation},
|
|
{"addition", AnimatedNodeType::Addition},
|
|
{"subtraction", AnimatedNodeType::Subtraction},
|
|
{"division", AnimatedNodeType::Division},
|
|
{"multiplication", AnimatedNodeType::Multiplication},
|
|
{"modulus", AnimatedNodeType::Modulus},
|
|
{"diffclamp", AnimatedNodeType::Diffclamp},
|
|
{"transform", AnimatedNodeType::Transform},
|
|
{"tracking", AnimatedNodeType::Tracking},
|
|
{"round", AnimatedNodeType::Round}};
|
|
|
|
if (auto iter = typeNames.find(nodeTypeName); iter != typeNames.end()) {
|
|
return iter->second;
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
} // namespace facebook::react
|