mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Reduce call to folly::dynamic::object insert and remove unnecessary AnimatedNode::update calls (#52270)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52270 ## Changelog: [Internal] [Changed] - Reduce call to `folly::dynamic::object` insert and remove unnecessary AnimatedNode::update calls Reviewed By: christophpurrer Differential Revision: D77315659 fbshipit-source-id: 656d7bcc957126ee8fa5a7463223273a93d31369
This commit is contained in:
1 parent
556957d458
commit
63d8d978f5
5 files changed
+13
-37
No files matched your search
+1
-5
@@ -123,11 +123,7 @@ void PropsAnimatedNode::update(bool forceFabricCommit) {
|
||||
case AnimatedNodeType::Style: {
|
||||
if (const auto& styleNode =
|
||||
manager_->getAnimatedNode<StyleAnimatedNode>(nodeTag)) {
|
||||
styleNode->update();
|
||||
auto& styleNodeProps = styleNode->getProps();
|
||||
for (const auto& styleNodeProp : styleNodeProps.items()) {
|
||||
props_.insert(styleNodeProp.first.c_str(), styleNodeProp.second);
|
||||
}
|
||||
styleNode->collectViewUpdates(props_);
|
||||
}
|
||||
} break;
|
||||
case AnimatedNodeType::Props:
|
||||
|
||||
+7
-12
@@ -38,10 +38,9 @@ StyleAnimatedNode::StyleAnimatedNode(
|
||||
Tag tag,
|
||||
const folly::dynamic& config,
|
||||
NativeAnimatedNodesManager& manager)
|
||||
: AnimatedNode(tag, config, manager, AnimatedNodeType::Style),
|
||||
props_(folly::dynamic::object()) {}
|
||||
: AnimatedNode(tag, config, manager, AnimatedNodeType::Style) {}
|
||||
|
||||
void StyleAnimatedNode::update() {
|
||||
void StyleAnimatedNode::collectViewUpdates(folly::dynamic& props) {
|
||||
const auto& style = getConfig()["style"];
|
||||
for (const auto& styleProp : style.items()) {
|
||||
auto propName = styleProp.first.asString();
|
||||
@@ -51,11 +50,7 @@ void StyleAnimatedNode::update() {
|
||||
case AnimatedNodeType::Transform: {
|
||||
if (const auto transformNode =
|
||||
manager_->getAnimatedNode<TransformAnimatedNode>(nodeTag)) {
|
||||
transformNode->update();
|
||||
auto& transformNodeProps = transformNode->getProps();
|
||||
for (const auto& styleNodeProp : transformNodeProps.items()) {
|
||||
props_.insert(styleNodeProp.first.c_str(), styleNodeProp.second);
|
||||
}
|
||||
transformNode->collectViewUpdates(props);
|
||||
}
|
||||
} break;
|
||||
case AnimatedNodeType::Value:
|
||||
@@ -71,18 +66,18 @@ void StyleAnimatedNode::update() {
|
||||
if (const auto valueNode =
|
||||
manager_->getAnimatedNode<ValueAnimatedNode>(nodeTag)) {
|
||||
if (valueNode->getIsColorValue()) {
|
||||
props_.insert(
|
||||
props.insert(
|
||||
propName.c_str(),
|
||||
static_cast<int32_t>(valueNode->getValue()));
|
||||
} else {
|
||||
props_.insert(propName.c_str(), valueNode->getValue());
|
||||
props.insert(propName.c_str(), valueNode->getValue());
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case AnimatedNodeType::Color: {
|
||||
if (const auto colorAnimNode =
|
||||
manager_->getAnimatedNode<ColorAnimatedNode>(nodeTag)) {
|
||||
props_.insert(
|
||||
props.insert(
|
||||
propName.c_str(),
|
||||
static_cast<int32_t>(colorAnimNode->getColor()));
|
||||
}
|
||||
@@ -95,7 +90,7 @@ void StyleAnimatedNode::update() {
|
||||
}
|
||||
}
|
||||
|
||||
layoutStyleUpdated_ = isLayoutPropsUpdated(props_);
|
||||
layoutStyleUpdated_ = isLayoutPropsUpdated(props);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
+1
-6
@@ -22,18 +22,13 @@ class StyleAnimatedNode final : public AnimatedNode {
|
||||
Tag tag,
|
||||
const folly::dynamic& config,
|
||||
NativeAnimatedNodesManager& manager);
|
||||
void update() override;
|
||||
|
||||
const folly::dynamic& getProps() const noexcept {
|
||||
return props_;
|
||||
}
|
||||
void collectViewUpdates(folly::dynamic& props);
|
||||
|
||||
bool isLayoutStyleUpdated() const noexcept {
|
||||
return layoutStyleUpdated_;
|
||||
}
|
||||
|
||||
private:
|
||||
folly::dynamic props_;
|
||||
bool layoutStyleUpdated_;
|
||||
};
|
||||
} // namespace facebook::react
|
||||
+3
-8
@@ -30,10 +30,9 @@ TransformAnimatedNode::TransformAnimatedNode(
|
||||
Tag tag,
|
||||
const folly::dynamic& config,
|
||||
NativeAnimatedNodesManager& manager)
|
||||
: AnimatedNode(tag, config, manager, AnimatedNodeType::Transform),
|
||||
props_(folly::dynamic::object()) {}
|
||||
: AnimatedNode(tag, config, manager, AnimatedNodeType::Transform) {}
|
||||
|
||||
void TransformAnimatedNode::update() {
|
||||
void TransformAnimatedNode::collectViewUpdates(folly::dynamic& props) {
|
||||
folly::dynamic transforms = folly::dynamic::array();
|
||||
auto transformsArray = getConfig()[sTransformsName];
|
||||
react_native_assert(transformsArray.type() == folly::dynamic::ARRAY);
|
||||
@@ -53,11 +52,7 @@ void TransformAnimatedNode::update() {
|
||||
transforms.push_back(folly::dynamic::object(property, value.value()));
|
||||
}
|
||||
}
|
||||
props_[sTransformPropName] = std::move(transforms);
|
||||
}
|
||||
|
||||
const folly::dynamic& TransformAnimatedNode::getProps() {
|
||||
return props_;
|
||||
props[sTransformPropName] = std::move(transforms);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
+1
-6
@@ -29,11 +29,6 @@ class TransformAnimatedNode final : public AnimatedNode {
|
||||
const folly::dynamic& config,
|
||||
NativeAnimatedNodesManager& manager);
|
||||
|
||||
void update() override;
|
||||
|
||||
const folly::dynamic& getProps();
|
||||
|
||||
private:
|
||||
folly::dynamic props_;
|
||||
void collectViewUpdates(folly::dynamic& props);
|
||||
};
|
||||
} // namespace facebook::react
|
||||
Reference in new issue
Block a user