Fabric: More strict policies to dirty Yoga nodes in YogaLayoutableShadowNode

Summary:
Yoga uses a dirty flag to re-layout nodes. In normal, single-threaded approach the policy for dirtying is simple: if a node was changed, we need to dirty it. In the Concurrent Yoga approach, those rules are not so simple, and it seems we haven't formalized those rules yet.

Investigating some layout issues that we have in Fabric, I tend to believe that we don't dirty as much we should. Hense this change adds mode dirtying.

Reviewed By: JoshuaGross

Differential Revision: D21092815

fbshipit-source-id: 4603c97ccb79efcdf5e6a4cc450ebe61b63effb3
This commit is contained in:
Valentin Shergin 2020-04-20 19:19:09 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 4afb8362ec
Коммит d639063499
1 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -54,6 +54,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
yogaNode_(&initializeYogaConfig(yogaConfig_)) {
yogaNode_.setContext(this);
// Newly created node must be `dirty` just becasue it is new.
// This is not a default for `YGNode`.
yogaNode_.setDirty(true);
updateYogaProps();
updateYogaChildren();
}
@ -140,8 +144,6 @@ void YogaLayoutableShadowNode::appendChildYogaNode(
return;
}
yogaNode_.setDirty(true);
auto yogaNodeRawPtr = &yogaNode_;
auto childYogaNodeRawPtr = &child.yogaNode_;
auto childNodePtr = const_cast<YogaLayoutableShadowNode *>(&child);
@ -180,6 +182,10 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
yogaNode_.setChildren({});
// We might undo this later at the end of the method if we can infer that
// dirting is not necessary here.
yogaNode_.setDirty(true);
auto i = int{0};
for (auto const &child : children) {
auto yogaLayoutableChild =
@ -321,8 +327,9 @@ YogaLayoutableShadowNode &YogaLayoutableShadowNode::cloneAndReplaceChild(
int suggestedIndex) {
auto clonedChildShadowNode = child.clone({});
replaceChild(child, clonedChildShadowNode, suggestedIndex);
return static_cast<YogaLayoutableShadowNode &>(*clonedChildShadowNode);
auto &node = static_cast<YogaLayoutableShadowNode &>(*clonedChildShadowNode);
node.yogaNode_.setDirty(true);
return node;
}
#pragma mark - Yoga Connectors