From 912bca05b1eae98cf9e3fdc34d8d65959632588f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 26 May 2023 09:06:00 -0700 Subject: [PATCH] Create version of LayoutableShadowNode::computeRelativeLayoutMetrics that works with an ancestor list (#37434) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37434 We'll be using this method in IntersectionObserver to avoid having to get the list of ancestor multiple times when calling computeRelativeLayoutMetrics for the target bounding rect and for the intersection rect. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D45866232 fbshipit-source-id: 0efa165b780e819bf19028fecd22b303ca6f52ad --- .../react/renderer/core/LayoutableShadowNode.cpp | 5 +++++ .../ReactCommon/react/renderer/core/LayoutableShadowNode.h | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp index 3bc848f4685..18374f9a286 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp @@ -105,7 +105,12 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics( } auto ancestors = descendantNodeFamily.getAncestors(ancestorNode); + return computeRelativeLayoutMetrics(ancestors, policy); +} +LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics( + AncestorList const &ancestors, + LayoutInspectingPolicy policy) { if (ancestors.empty()) { // Specified nodes do not form an ancestor-descender relationship // in the same tree. Aborting. diff --git a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h index b16213ad8f8..7bb9e0f0d9f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h @@ -62,6 +62,13 @@ class LayoutableShadowNode : public ShadowNode { LayoutableShadowNode const &ancestorNode, LayoutInspectingPolicy policy); + /* + * Computes the layout metrics of a node relative to its specified ancestors. + */ + static LayoutMetrics computeRelativeLayoutMetrics( + AncestorList const &ancestors, + LayoutInspectingPolicy policy); + /* * Performs layout of the tree starting from this node. Usually is being * called on the root node.