Skip to content
Open
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
40 changes: 40 additions & 0 deletions packages/react-native-renderer/src/ReactFiberConfigFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,10 @@ export type FragmentInstanceType = {
observeUsing: (observer: IntersectionObserver) => void,
unobserveUsing: (observer: IntersectionObserver) => void,
compareDocumentPosition: (otherNode: PublicInstance) => number,
getRootNode(getRootNodeOptions?: {
composed: boolean,
}): Node | FragmentInstanceType,
getClientRects: () => Array<DOMRect>,
};

function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) {
Expand Down Expand Up @@ -754,6 +758,42 @@ function collectChildren(child: Fiber, collection: Array<Fiber>): boolean {
return false;
}

// $FlowFixMe[prop-missing]
FragmentInstance.prototype.getRootNode = function (
this: FragmentInstanceType,
getRootNodeOptions?: {composed: boolean},
): Node | FragmentInstanceType {
const parentHostFiber = getFragmentParentHostFiber(this._fragmentFiber);
if (parentHostFiber === null) {
return this;
}
const parentHostInstance = getPublicInstanceFromHostFiber(parentHostFiber);
// $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
const rootNode = (parentHostInstance.getRootNode(getRootNodeOptions): Node);
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