Skip to content

Commit

Permalink
Fabric: More strict policies to dirty Yoga nodes in YogaLayoutableSha…
Browse files Browse the repository at this point in the history
…dowNode

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
  • Loading branch information
shergin authored and facebook-github-bot committed Apr 21, 2020
1 parent 4afb836 commit d639063
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -140,8 +144,6 @@ void YogaLayoutableShadowNode::appendChildYogaNode(
return;
}

yogaNode_.setDirty(true);

auto yogaNodeRawPtr = &yogaNode_;
auto childYogaNodeRawPtr = &child.yogaNode_;
auto childNodePtr = const_cast<YogaLayoutableShadowNode *>(&child);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d639063

Please sign in to comment.