From 13d9b16f3892cfdeb125454185fecac4e095e59d Mon Sep 17 00:00:00 2001 From: Jack Pope Date: Fri, 19 Sep 2025 17:51:28 -0400 Subject: [PATCH] Add getClientRects to fabric fragment instance We only have getBoundingClientRect available from RN currently. This should work as a substitute for this case because the equivalent of multi-rect elements in RN is a nested Text component. We only include the rects of top-level host components here so we can assume that calling getBoundingClientRect on each child is the same result. --- .../src/ReactFiberConfigFabric.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/react-native-renderer/src/ReactFiberConfigFabric.js b/packages/react-native-renderer/src/ReactFiberConfigFabric.js index e6ac1901c522d..0f334eea86024 100644 --- a/packages/react-native-renderer/src/ReactFiberConfigFabric.js +++ b/packages/react-native-renderer/src/ReactFiberConfigFabric.js @@ -648,6 +648,7 @@ export type FragmentInstanceType = { getRootNode(getRootNodeOptions?: { composed: boolean, }): Node | FragmentInstanceType, + getClientRects: () => Array, }; function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) { @@ -772,6 +773,27 @@ FragmentInstance.prototype.getRootNode = function ( return rootNode; }; +// $FlowFixMe[prop-missing] +FragmentInstance.prototype.getClientRects = function ( + this: FragmentInstanceType, +): Array { + const rects: Array = []; + traverseFragmentInstance(this._fragmentFiber, collectClientRects, rects); + return rects; +}; +function collectClientRects(child: Fiber, rects: Array): boolean { + const instance = getPublicInstanceFromHostFiber(child); + + // getBoundingClientRect is available on Fabric instances while getClientRects is not. + // This should work as a substitute in this case because the only equivalent of a multi-rect + // element in RN would be a nested Text component. + // Since we only use top-level nodes here, we can assume that getBoundingClientRect is sufficient. + // $FlowFixMe[method-unbinding] + // $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque + rects.push(instance.getBoundingClientRect()); + return false; +} + export function createFragmentInstance( fragmentFiber: Fiber, ): FragmentInstanceType {