Skip to content

Commit 318e441

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 03e3d6f commit 318e441

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
@@ -638,6 +638,9 @@ export type FragmentInstanceType = {
638638
observeUsing: (observer: IntersectionObserver) => void,
639639
unobserveUsing: (observer: IntersectionObserver) => void,
640640
compareDocumentPosition: (otherNode: PublicInstance) => number,
641+
getRootNode(getRootNodeOptions?: {
642+
composed: boolean,
643+
}): Node | FragmentInstanceType,
641644
};
642645

643646
function FragmentInstance(this: FragmentInstanceType, fragmentFiber: Fiber) {
@@ -747,6 +750,21 @@ function collectChildren(child: Fiber, collection: Array<Fiber>): boolean {
747750
return false;
748751
}
749752

753+
// $FlowFixMe[prop-missing]
754+
FragmentInstance.prototype.getRootNode = function (
755+
this: FragmentInstanceType,
756+
getRootNodeOptions?: {composed: boolean},
757+
): Node | FragmentInstanceType {
758+
const parentHostFiber = getFragmentParentHostFiber(this._fragmentFiber);
759+
if (parentHostFiber === null) {
760+
return this;
761+
}
762+
const parentHostInstance = getPublicInstanceFromHostFiber(parentHostFiber);
763+
// $FlowFixMe[incompatible-use] Fabric PublicInstance is opaque
764+
const rootNode = (parentHostInstance.getRootNode(getRootNodeOptions): Node);
765+
return rootNode;
766+
};
767+
750768
export function createFragmentInstance(
751769
fragmentFiber: Fiber,
752770
): FragmentInstanceType {

0 commit comments

Comments
 (0)