Fabric: Checking for HasNewLayout before applying layout metrics to ShadowNode

Summary:
If the `HasNewLayout` flag is `false`, we should not copy the data from YGStyle/YGLayout to ShadowNode because the node can be already sealed and because it's unnecessary. Previously we workaround this case with a special check in `setLayoutMetrics` method, but that can be unreliable because of some side-effects related to pixel rounding and comparing floats.
The new approach is much more robust and explicit.

Reviewed By: JoshuaGross

Differential Revision: D14496939

fbshipit-source-id: deddb14d2206c5bd3f22154d0ea682e3c5888901
This commit is contained in:
Valentin Shergin
2019-03-18 19:21:26 -07:00
committed by Facebook Github Bot
parent be6fa25d16
commit 55eaf30740
2 changed files with 6 additions and 2 deletions
@@ -170,6 +170,10 @@ void YogaLayoutableShadowNode::layout(LayoutContext layoutContext) {
void YogaLayoutableShadowNode::layoutChildren(LayoutContext layoutContext) {
for (const auto &childYogaNode : yogaNode_.getChildren()) {
if (!childYogaNode->getHasNewLayout()) {
continue;
}
auto childNode =
static_cast<YogaLayoutableShadowNode *>(childYogaNode->getContext());
@@ -22,12 +22,12 @@ LayoutMetrics LayoutableShadowNode::getLayoutMetrics() const {
}
bool LayoutableShadowNode::setLayoutMetrics(LayoutMetrics layoutMetrics) {
ensureUnsealed();
if (layoutMetrics_ == layoutMetrics) {
return false;
}
ensureUnsealed();
layoutMetrics_ = layoutMetrics;
return true;
}