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
This commit is contained in:
Rubén Norte
2023-05-26 09:06:00 -07:00
committed by Facebook GitHub Bot
parent 37d582dccd
commit 912bca05b1
2 changed files with 12 additions and 0 deletions
@@ -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.
@@ -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.