Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/react-native-renderer/src/ReactFiberConfigFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ export type FragmentInstanceType = {
getRootNode(getRootNodeOptions?: {
composed: boolean,
}): Node | FragmentInstanceType,
getClientRects: () => Array<DOMRect>,
};

function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) {
Expand Down Expand Up @@ -772,6 +773,27 @@ FragmentInstance.prototype.getRootNode = function (
return rootNode;
};

// $FlowFixMe[prop-missing]
FragmentInstance.prototype.getClientRects = function (
this: FragmentInstanceType,
): Array<DOMRect> {
const rects: Array<DOMRect> = [];
traverseFragmentInstance(this._fragmentFiber, collectClientRects, rects);
return rects;
};
function collectClientRects(child: Fiber, rects: Array<DOMRect>): 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 {
Expand Down
Loading