Refactor cloning of YogaNode

Summary: see Test Plan

Reviewed By: priteshrnandgaonkar

Differential Revision: D7339832

fbshipit-source-id: 2de6f47ae7601ac083d3b9fbe10ffaf6307ae760
This commit is contained in:
David Vacca
2018-04-01 18:27:04 -07:00
committed by Facebook Github Bot
parent 187fc54596
commit 17901ea5c2
9 changed files with 103 additions and 59 deletions

View File

@@ -558,15 +558,18 @@ void YGNode::cloneChildrenIfNeeded() {
return;
}
const YGNodeClonedFunc cloneNodeCallback = config_->cloneNodeCallback;
const YGCloneNodeFunc cloneNodeCallback = config_->cloneNodeCallback;
for (uint32_t i = 0; i < childCount; ++i) {
const YGNodeRef oldChild = children_[i];
const YGNodeRef newChild = YGNodeClone(oldChild);
YGNodeRef newChild = nullptr;
if (cloneNodeCallback) {
newChild = cloneNodeCallback(oldChild, this, i);
}
if (newChild == nullptr) {
newChild = YGNodeClone(oldChild);
}
replaceChild(newChild, i);
newChild->setParent(this);
if (cloneNodeCallback) {
cloneNodeCallback(oldChild, newChild, this, i);
}
}
}