From 0d33cdf146a73de562b811e99cf9b8ee02d8e3a9 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 9 Mar 2020 16:32:33 -0700 Subject: [PATCH] Fabric: New `LayoutableShadowNode::measure(...)` which measures the node "outside" Summary: This diff introduces a new method of `LayoutableShadowNode` called `measure`. The purpose of the method is to measure the node from an "outside" perspective (including paddings and so on). The existing method with the same name (but with slightly different signature) will be renamed to `measureContent` in future diffs. Hense we will have two `measure*` methods: * `measureContent` measures nested content of the node; * `measure` measures the node (outside). This diff also introduces a default implementation of a new measure that uses `layoutTree` under the hood. Measures the node with given layoutConstraints and layoutContext. The size of nested content and the padding should be included, the margin should *not* be included. Changelog: [Internal] Fabric-specific internal change. Reviewed By: JoshuaGross, sammy-SC Differential Revision: D20268047 fbshipit-source-id: 29c28cf16c5afe24f1bfb6e76c42816d4583a8fa --- .../fabric/core/layout/LayoutableShadowNode.cpp | 15 +++++++++++++++ .../fabric/core/layout/LayoutableShadowNode.h | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp index b630cd29f4..0c699a935e 100644 --- a/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp +++ b/ReactCommon/fabric/core/layout/LayoutableShadowNode.cpp @@ -156,6 +156,21 @@ Size LayoutableShadowNode::measure(LayoutConstraints layoutConstraints) const { return Size(); } +Size LayoutableShadowNode::measure( + LayoutContext const &layoutContext, + LayoutConstraints const &layoutConstraints) const { + auto clonedShadowNode = clone({}); + auto &layoutableShadowNode = + static_cast(*clonedShadowNode); + + auto localLayoutContext = layoutContext; + localLayoutContext.affectedNodes = nullptr; + + layoutableShadowNode.layoutTree(localLayoutContext, layoutConstraints); + + return layoutableShadowNode.getLayoutMetrics().frame.size; +} + Float LayoutableShadowNode::firstBaseline(Size size) const { return 0; } diff --git a/ReactCommon/fabric/core/layout/LayoutableShadowNode.h b/ReactCommon/fabric/core/layout/LayoutableShadowNode.h index ea30b49295..78767275c7 100644 --- a/ReactCommon/fabric/core/layout/LayoutableShadowNode.h +++ b/ReactCommon/fabric/core/layout/LayoutableShadowNode.h @@ -68,6 +68,15 @@ class LayoutableShadowNode : public ShadowNode { */ virtual Size measure(LayoutConstraints layoutConstraints) const; + /* + * Measures the node with given `layoutContext` and `layoutConstraints`. + * The size of nested content and the padding should be included, the margin + * should *not* be included. Default implementation returns zero size. + */ + virtual Size measure( + LayoutContext const &layoutContext, + LayoutConstraints const &layoutConstraints) const; + /* * Computes layout recursively. * Additional environmental constraints might be provided via `layoutContext`