diff --git a/packages/react-native-fantom/src/__tests__/Fantom-itest.js b/packages/react-native-fantom/src/__tests__/Fantom-itest.js index e9005ac7e1b..e2042ca8ba2 100644 --- a/packages/react-native-fantom/src/__tests__/Fantom-itest.js +++ b/packages/react-native-fantom/src/__tests__/Fantom-itest.js @@ -15,7 +15,7 @@ import type {Root} from '..'; import Fantom from '..'; import * as React from 'react'; -import {ScrollView, Text, TextInput, View} from 'react-native'; +import {Modal, ScrollView, Text, TextInput, View} from 'react-native'; import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom'; import ensureInstance from 'react-native/src/private/utilities/ensureInstance'; import ReactNativeDocument from 'react-native/src/private/webapis/dom/nodes/ReactNativeDocument'; @@ -671,4 +671,72 @@ describe('Fantom', () => { expect(onLayout).toHaveBeenCalledTimes(1); }); }); + describe('enqueueModalSizeUpdate', () => { + it('throws error if called on node that is not ', () => { + const root = Fantom.createRoot(); + let maybeNode; + + Fantom.runTask(() => { + root.render( + { + maybeNode = node; + }} + />, + ); + }); + + const element = ensureInstance(maybeNode, ReactNativeElement); + + expect(() => { + Fantom.runOnUIThread(() => { + Fantom.enqueueModalSizeUpdate(element, { + width: 200, + height: 100, + }); + }); + }).toThrow( + 'Exception in HostFunction: enqueueModalSizeUpdate() can only be called on ', + ); + }); + + it('change size of ', () => { + const root = Fantom.createRoot(); + let maybeModalNode; + let maybeViewNode; + + Fantom.runTask(() => { + root.render( + ) => { + maybeModalNode = node; + }}> + { + maybeViewNode = node; + }} + /> + , + ); + }); + + const modalElement = ensureInstance(maybeModalNode, ReactNativeElement); + + Fantom.runOnUIThread(() => { + Fantom.enqueueModalSizeUpdate(modalElement, { + width: 100, + height: 100, + }); + }); + + Fantom.runWorkLoop(); + + const viewElement = ensureInstance(maybeViewNode, ReactNativeElement); + + const boundingClientRect = viewElement.getBoundingClientRect(); + expect(boundingClientRect.height).toBe(25); + expect(boundingClientRect.width).toBe(50); + }); + }); }); diff --git a/packages/react-native-fantom/src/index.js b/packages/react-native-fantom/src/index.js index c5303cfbd61..837f7b62daf 100644 --- a/packages/react-native-fantom/src/index.js +++ b/packages/react-native-fantom/src/index.js @@ -237,6 +237,14 @@ function scrollTo( NativeFantom.scrollTo(shadowNode, options); } +function enqueueModalSizeUpdate( + node: ReactNativeElement, + size: {width: number, height: number}, +) { + const shadowNode = getNativeNodeReference(node); + NativeFantom.enqueueModalSizeUpdate(shadowNode, size.width, size.height); +} + export const unstable_benchmark = Benchmark; type FantomConstants = $ReadOnly<{ @@ -336,6 +344,7 @@ export default { dispatchNativeEvent, enqueueNativeEvent, flushAllNativeEvents, + enqueueModalSizeUpdate, unstable_benchmark: Benchmark, scrollTo, saveJSMemoryHeapSnapshot, diff --git a/packages/react-native/src/private/testing/fantom/specs/NativeFantom.js b/packages/react-native/src/private/testing/fantom/specs/NativeFantom.js index 7fcc5169891..a8909f3f395 100644 --- a/packages/react-native/src/private/testing/fantom/specs/NativeFantom.js +++ b/packages/react-native/src/private/testing/fantom/specs/NativeFantom.js @@ -76,6 +76,11 @@ interface Spec extends TurboModule { shadowNode: mixed /* ShadowNode */, options: ScrollOptions, ) => void; + enqueueModalSizeUpdate: ( + shadowNode: mixed /* ShadowNode */, + height: number, + width: number, + ) => void; takeMountingManagerLogs: (surfaceId: number) => Array; flushMessageQueue: () => void; flushEventQueue: () => void;