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
This commit is contained in:
Valentin Shergin 2018-04-10 12:45:56 -07:00 committed by Facebook Github Bot
parent ef6b916e48
commit 0332d475cc
1 changed files with 7 additions and 8 deletions

View File

@ -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<YGNode>(*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<YGNode>(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