Skip to content

Commit 1ca267f

Browse files
committed
Add getRootNode to fabric fragment instance
This is the same approach as DOM, where we call getRootNode on the parent. Tests are in react-native using Fantom.
1 parent 8bb7241 commit 1ca267f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ export type FragmentInstanceType = {
645645
observeUsing: (observer: IntersectionObserver) => void,
646646
unobserveUsing: (observer: IntersectionObserver) => void,
647647
compareDocumentPosition: (otherNode: PublicInstance) => number,
648+
getRootNode(getRootNodeOptions?: {
649+
composed: boolean,
650+
}): Node | FragmentInstanceType,
648651
};
649652

650653
function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) {
@@ -754,6 +757,21 @@ function collectChildren(child: Fiber, collection: Array<Fiber>): boolean {
754757
return false;
755758
}
756759

760+
// $FlowFixMe[prop-missing]
761+
FragmentInstance.prototype.getRootNode = function (
762+
this: FragmentInstanceType,
763+
getRootNodeOptions?: {composed: boolean},
764+
): Node | FragmentInstanceType {
765+
const parentHostFiber = getFragmentParentHostFiber(this._fragmentFiber);
766+
if (parentHostFiber === null) {
767+
return this;
768+
}
769+
const parentHostInstance = getPublicInstanceFromHostFiber(parentHostFiber);
770+
// $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
771+
const rootNode = (parentHostInstance.getRootNode(getRootNodeOptions): Node);
772+
return rootNode;
773+
};
774+
757775
export function createFragmentInstance(
758776
fragmentFiber: Fiber,
759777
): FragmentInstanceType {

0 commit comments

Comments
 (0)