From 55eaf30740b1ac13d7b6a29073bb5089b72cafb8 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 18 Mar 2019 19:16:40 -0700 Subject: [PATCH] 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 --- .../fabric/components/view/yoga/YogaLayoutableShadowNode.cpp | 4 ++++ ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index fdbc1310501..df38fa0a9b2 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -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(childYogaNode->getContext()); diff --git a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp index 13296abc4b8..b6220fe5389 100644 --- a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp +++ b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp @@ -22,12 +22,12 @@ LayoutMetrics LayoutableShadowNode::getLayoutMetrics() const { } bool LayoutableShadowNode::setLayoutMetrics(LayoutMetrics layoutMetrics) { + ensureUnsealed(); + if (layoutMetrics_ == layoutMetrics) { return false; } - ensureUnsealed(); - layoutMetrics_ = layoutMetrics; return true; }