Fabric: YogaLayoutableShadowNode::updateYogaChildren

Summary:
Similar to a previous diff but for `setChildren`.
`YogaLayoutableShadowNode::setChildren()` was renamed to `YogaLayoutableShadowNode::updateYogaChildren()`. Now we don't need to pass an argument to this function because the object is already initialized. The new name also disambiguates this method with `getChildren()` from `ShadowNode` (which does something completely different). The rest of the changes is just type adjustments.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052031

fbshipit-source-id: 6157cad9b55d4cdd97ce04e1278ac1369bfb96bc
This commit is contained in:
Valentin Shergin
2020-02-26 22:08:21 -08:00
committed by Facebook Github Bot
parent 191d65ec4e
commit 6a88e94326
2 changed files with 21 additions and 21 deletions
@@ -37,7 +37,7 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
yogaNode_.setContext(this);
updateYogaProps();
setChildren(YogaLayoutableShadowNode::getYogaLayoutableChildren());
updateYogaChildren();
}
YogaLayoutableShadowNode::YogaLayoutableShadowNode(
@@ -62,7 +62,7 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
}
if (fragment.children) {
setChildren(YogaLayoutableShadowNode::getYogaLayoutableChildren());
updateYogaChildren();
}
}
@@ -103,13 +103,12 @@ void YogaLayoutableShadowNode::appendChild(ShadowNode::Shared const &child) {
auto yogaLayoutableChild =
traitCast<YogaLayoutableShadowNode const *>(child.get());
if (yogaLayoutableChild) {
appendChildYogaNode(
*const_cast<YogaLayoutableShadowNode *>(yogaLayoutableChild));
appendChildYogaNode(*yogaLayoutableChild);
}
}
void YogaLayoutableShadowNode::appendChildYogaNode(
YogaLayoutableShadowNode &child) {
YogaLayoutableShadowNode const &child) {
ensureUnsealed();
if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
@@ -122,7 +121,7 @@ void YogaLayoutableShadowNode::appendChildYogaNode(
auto yogaNodeRawPtr = &yogaNode_;
auto childYogaNodeRawPtr = &child.yogaNode_;
auto childNodePtr = &child;
auto childNodePtr = const_cast<YogaLayoutableShadowNode *>(&child);
if (childYogaNodeRawPtr->getOwner() != nullptr) {
childNodePtr =
@@ -154,14 +153,15 @@ YogaLayoutableShadowNode::getYogaLayoutableChildren() const {
return layoutableChildren;
}
void YogaLayoutableShadowNode::setChildren(
YogaLayoutableShadowNode::UnsharedList children) {
void YogaLayoutableShadowNode::updateYogaChildren() {
if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
return;
}
ensureUnsealed();
auto &children = getChildren();
// Optimization:
// If the new list of child nodes consists of clean nodes, and if their styles
// are identical to styles of old children, we don't dirty the node.
@@ -173,10 +173,18 @@ void YogaLayoutableShadowNode::setChildren(
auto i = int{0};
for (auto const &child : children) {
appendChildYogaNode(*child);
auto yogaLayoutableChild =
traitCast<YogaLayoutableShadowNode const *>(child.get());
isClean = isClean && !child->yogaNode_.isDirty() &&
child->yogaNode_.getStyle() == oldChildren[i++]->getStyle();
if (!yogaLayoutableChild) {
continue;
}
appendChildYogaNode(*yogaLayoutableChild);
isClean = isClean && !yogaLayoutableChild->yogaNode_.isDirty() &&
yogaLayoutableChild->yogaNode_.getStyle() ==
oldChildren[i++]->getStyle();
}
yogaNode_.setDirty(!isClean);
@@ -51,16 +51,8 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {
void appendChild(ShadowNode::Shared const &child);
/*
* Sets Yoga children based on collection of `YogaLayoutableShadowNode`
* instances. Complements `ShadowNode::setChildren(...)` functionality from
* Yoga perspective.
*/
void setChildren(YogaLayoutableShadowNode::UnsharedList children);
void updateYogaChildren();
/*
*
*/
void updateYogaProps();
/*
@@ -113,7 +105,7 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {
* Complements `ShadowNode::appendChild(...)` functionality from Yoga
* perspective.
*/
void appendChildYogaNode(YogaLayoutableShadowNode &child);
void appendChildYogaNode(YogaLayoutableShadowNode const &child);
YogaLayoutableShadowNode &cloneAndReplaceChild(
YogaLayoutableShadowNode &child,