From 0332d475ccfbbe4ec7649e1b80c02a142294a025 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 10 Apr 2018 12:45:56 -0700 Subject: [PATCH] Fabric: Refined Yoga's `isDirty` flag management in YogaLayoutableShadowNode Summary: Motivation: * We never should call `markDirtyAndPropogate()` during tree construction/mutation because it might affect trees in different thread/dimentions; * In Fabric we basically always have to dirty nodes ourselves manually duting tree construction; * In Fabric we don't have "scoped/limited" tree mutations which require recursive dirtying; any mutation is creation of the new tree instance; * Default value of the `isDirty` flag is "false", so we have to change this right after creation of Yoga node (and after cloning). Reviewed By: mdvacca Differential Revision: D7467797 fbshipit-source-id: 2c9144271dceea6ba2b95173209b99b5d86fbd87 --- .../fabric/view/yoga/YogaLayoutableShadowNode.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.cpp index 9aadda4d8..71e5ac89b 100644 --- a/ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/view/yoga/YogaLayoutableShadowNode.cpp @@ -42,7 +42,7 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( yogaNode->setConfig(suitableYogaConfig().get()); yogaNode->setStyle(props->getYogaStyle()); yogaNode->setContext(this); - yogaNode->markDirtyAndPropogate(); + yogaNode->setDirty(true); YogaLayoutableShadowNode::setYogaNodeChildrenBasedOnShadowNodeChildren(*yogaNode, children); yogaNode_ = yogaNode; } @@ -53,8 +53,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( const SharedShadowNodeSharedList &children ) { auto yogaNode = std::make_shared(*shadowNode->yogaNode_); + yogaNode->setConfig(suitableYogaConfig().get()); yogaNode->setContext(this); yogaNode->setOwner(nullptr); + yogaNode->setDirty(true); if (props) { yogaNode->setStyle(props->getYogaStyle()); @@ -64,8 +66,6 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( YogaLayoutableShadowNode::setYogaNodeChildrenBasedOnShadowNodeChildren(*yogaNode, children); } - yogaNode->markDirtyAndPropogate(); - yogaNode_ = yogaNode; } @@ -98,9 +98,9 @@ void YogaLayoutableShadowNode::appendChild(SharedYogaLayoutableShadowNode child) auto nonConstChildYogaNode = std::const_pointer_cast(child->yogaNode_); nonConstYogaNode->insertChild(nonConstChildYogaNode.get(), nonConstYogaNode->getChildrenCount()); - if (nonConstChildYogaNode->getParent() == nullptr) { + if (nonConstChildYogaNode->getOwner() == nullptr) { child->ensureUnsealed(); - nonConstChildYogaNode->setParent(nonConstYogaNode.get()); + nonConstChildYogaNode->setOwner(nonConstYogaNode.get()); } } @@ -220,14 +220,13 @@ void YogaLayoutableShadowNode::setYogaNodeChildrenBasedOnShadowNodeChildren(YGNo yogaNodeChildren.push_back(yogaNodeChild); - if (yogaNodeChild->getParent() == nullptr) { + if (yogaNodeChild->getOwner() == nullptr) { yogaLayoutableShadowNode->ensureUnsealed(); - yogaNodeChild->setParent(&yogaNode); + yogaNodeChild->setOwner(&yogaNode); } } yogaNode.setChildren(yogaNodeChildren); - yogaNode.markDirtyAndPropogate(); } } // namespace react