From 6a88e943260be6d8498ab78ee4ea76cbb879d385 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Feb 2020 22:03:14 -0800 Subject: [PATCH] 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 --- .../view/yoga/YogaLayoutableShadowNode.cpp | 30 ++++++++++++------- .../view/yoga/YogaLayoutableShadowNode.h | 12 ++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index 3a7fa622604..ada014a16ae 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -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(child.get()); if (yogaLayoutableChild) { - appendChildYogaNode( - *const_cast(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(&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(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); diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h index b75981b79fc..28da5d3c1e6 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h @@ -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,