1010
1111import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment' ;
1212
13- import type { HostInstance } from 'react-native' ;
13+ import type { HostInstance } from 'react-native' ;
1414
1515import ensureInstance from '../../../__tests__/utilities/ensureInstance' ;
1616import * as Fantom from '@react-native/fantom' ;
1717import * as React from 'react' ;
18- import { View } from 'react-native' ;
19- import { createPortal } from 'react-native/Libraries/ReactNative/RendererProxy' ;
18+ import { View } from 'react-native' ;
19+ import { createPortal } from 'react-native/Libraries/ReactNative/RendererProxy' ;
2020import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement' ;
2121
22- function getTargetTag ( ref : { current : HostInstance | null } ) : number {
22+ function getTargetTag ( ref : { current : HostInstance | null } ) : number {
2323 const element = ensureInstance ( ref . current , ReactNativeElement ) ;
2424 return element . __nativeTag ;
2525}
@@ -28,9 +28,9 @@ describe('Portal', () => {
2828 test ( 'renders children into target view' , ( ) => {
2929 const root = Fantom . createRoot ( ) ;
3030 let targetTag : ?number = null ;
31- const targetRef = React . createRef < HostInstance > ( ) ;
31+ const targetRef = React . createRef < HostInstance > ( ) ;
3232
33- function TestComponent ( { showPortal } : { showPortal : boolean } ) {
33+ function TestComponent ( { showPortal} : { showPortal : boolean } ) {
3434 React . useLayoutEffect ( ( ) => {
3535 if ( targetRef . current ) {
3636 targetTag = getTargetTag ( targetRef ) ;
@@ -41,10 +41,7 @@ describe('Portal', () => {
4141 < View nativeID = "root" >
4242 < View >
4343 { showPortal && targetTag != null
44- ? createPortal (
45- < View nativeID = "portaled-child" /> ,
46- targetTag ,
47- )
44+ ? createPortal ( < View nativeID = "portaled-child" /> , targetTag )
4845 : null }
4946 </ View >
5047 < View ref = { targetRef } nativeID = "target" collapsable = { false } />
@@ -67,13 +64,13 @@ describe('Portal', () => {
6764 // Portal child should appear inside the target view
6865 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
6966 type : 'View' ,
70- props : { nativeID : 'root' } ,
67+ props : { nativeID : 'root' } ,
7168 children : [
7269 {
7370 type : 'View' ,
74- props : { nativeID : 'target' } ,
71+ props : { nativeID : 'target' } ,
7572 children : [
76- { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
73+ { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
7774 ] ,
7875 } ,
7976 ] ,
@@ -83,9 +80,9 @@ describe('Portal', () => {
8380 test ( 'unmounts portal children from target view' , ( ) => {
8481 const root = Fantom . createRoot ( ) ;
8582 let targetTag : ?number = null ;
86- const targetRef = React . createRef < HostInstance > ( ) ;
83+ const targetRef = React . createRef < HostInstance > ( ) ;
8784
88- function TestComponent ( { showPortal } : { showPortal : boolean } ) {
85+ function TestComponent ( { showPortal} : { showPortal : boolean } ) {
8986 React . useLayoutEffect ( ( ) => {
9087 if ( targetRef . current ) {
9188 targetTag = getTargetTag ( targetRef ) ;
@@ -96,10 +93,7 @@ describe('Portal', () => {
9693 < View nativeID = "root" >
9794 < View >
9895 { showPortal && targetTag != null
99- ? createPortal (
100- < View nativeID = "portaled-child" /> ,
101- targetTag ,
102- )
96+ ? createPortal ( < View nativeID = "portaled-child" /> , targetTag )
10397 : null }
10498 </ View >
10599 < View ref = { targetRef } nativeID = "target" collapsable = { false } />
@@ -120,13 +114,13 @@ describe('Portal', () => {
120114
121115 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
122116 type : 'View' ,
123- props : { nativeID : 'root' } ,
117+ props : { nativeID : 'root' } ,
124118 children : [
125119 {
126120 type : 'View' ,
127- props : { nativeID : 'target' } ,
121+ props : { nativeID : 'target' } ,
128122 children : [
129- { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
123+ { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
130124 ] ,
131125 } ,
132126 ] ,
@@ -140,26 +134,24 @@ describe('Portal', () => {
140134 // Portal child should be removed from target view
141135 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
142136 type : 'View' ,
143- props : { nativeID : 'root' } ,
144- children : [
145- { type : 'View' , props : { nativeID : 'target' } , children : [ ] } ,
146- ] ,
137+ props : { nativeID : 'root' } ,
138+ children : [ { type : 'View' , props : { nativeID : 'target' } , children : [ ] } ] ,
147139 } ) ;
148140 } ) ;
149141
150142 test ( 'preserves React context through portals' , ( ) => {
151143 const root = Fantom . createRoot ( ) ;
152144 let targetTag : ?number = null ;
153145 let capturedTheme : ?string = null ;
154- const targetRef = React . createRef < HostInstance > ( ) ;
155- const ThemeContext = React . createContext < string > ( 'light' ) ;
146+ const targetRef = React . createRef < HostInstance > ( ) ;
147+ const ThemeContext = React . createContext < string > ( 'light' ) ;
156148
157149 function ContextReader ( ) {
158150 capturedTheme = React . useContext ( ThemeContext ) ;
159151 return < View nativeID = "context-child" /> ;
160152 }
161153
162- function TestComponent ( { showPortal } : { showPortal : boolean } ) {
154+ function TestComponent ( { showPortal} : { showPortal : boolean } ) {
163155 React . useLayoutEffect ( ( ) => {
164156 if ( targetRef . current ) {
165157 targetTag = getTargetTag ( targetRef ) ;
@@ -194,7 +186,7 @@ describe('Portal', () => {
194186 test ( 'does not duplicate portal children on re-render and updates content' , ( ) => {
195187 const root = Fantom . createRoot ( ) ;
196188 let targetTag : ?number = null ;
197- const targetRef = React . createRef < HostInstance > ( ) ;
189+ const targetRef = React . createRef < HostInstance > ( ) ;
198190
199191 function TestComponent ( {
200192 showPortal,
@@ -214,9 +206,9 @@ describe('Portal', () => {
214206 < View >
215207 { showPortal && targetTag != null
216208 ? createPortal (
217- < View nativeID = { 'portaled-' + counter } /> ,
218- targetTag ,
219- )
209+ < View nativeID = { 'portaled-' + counter } /> ,
210+ targetTag ,
211+ )
220212 : null }
221213 </ View >
222214 < View ref = { targetRef } nativeID = "target" collapsable = { false } />
@@ -236,16 +228,16 @@ describe('Portal', () => {
236228
237229 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
238230 type : 'View' ,
239- props : { nativeID : 'root' } ,
231+ props : { nativeID : 'root' } ,
240232 children : [
241233 {
242234 type : 'View' ,
243- props : { nativeID : 'target' } ,
235+ props : { nativeID : 'target' } ,
244236 children : [
245- { type : 'View' , props : { nativeID : 'portaled-0' } , children : [ ] } ,
237+ { type : 'View' , props : { nativeID : 'portaled-0' } , children : [ ] } ,
246238 ] ,
247239 } ,
248- { type : 'View' , props : { nativeID : 'counter-0' } , children : [ ] } ,
240+ { type : 'View' , props : { nativeID : 'counter-0' } , children : [ ] } ,
249241 ] ,
250242 } ) ;
251243
@@ -256,16 +248,16 @@ describe('Portal', () => {
256248
257249 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
258250 type : 'View' ,
259- props : { nativeID : 'root' } ,
251+ props : { nativeID : 'root' } ,
260252 children : [
261253 {
262254 type : 'View' ,
263- props : { nativeID : 'target' } ,
255+ props : { nativeID : 'target' } ,
264256 children : [
265- { type : 'View' , props : { nativeID : 'portaled-1' } , children : [ ] } ,
257+ { type : 'View' , props : { nativeID : 'portaled-1' } , children : [ ] } ,
266258 ] ,
267259 } ,
268- { type : 'View' , props : { nativeID : 'counter-1' } , children : [ ] } ,
260+ { type : 'View' , props : { nativeID : 'counter-1' } , children : [ ] } ,
269261 ] ,
270262 } ) ;
271263
@@ -276,26 +268,26 @@ describe('Portal', () => {
276268
277269 expect ( root . getRenderedOutput ( ) . toJSON ( ) ) . toEqual ( {
278270 type : 'View' ,
279- props : { nativeID : 'root' } ,
271+ props : { nativeID : 'root' } ,
280272 children : [
281273 {
282274 type : 'View' ,
283- props : { nativeID : 'target' } ,
275+ props : { nativeID : 'target' } ,
284276 children : [
285- { type : 'View' , props : { nativeID : 'portaled-2' } , children : [ ] } ,
277+ { type : 'View' , props : { nativeID : 'portaled-2' } , children : [ ] } ,
286278 ] ,
287279 } ,
288- { type : 'View' , props : { nativeID : 'counter-2' } , children : [ ] } ,
280+ { type : 'View' , props : { nativeID : 'counter-2' } , children : [ ] } ,
289281 ] ,
290282 } ) ;
291283 } ) ;
292284
293285 test ( 'mount and unmount cycle works multiple times' , ( ) => {
294286 const root = Fantom . createRoot ( ) ;
295287 let targetTag : ?number = null ;
296- const targetRef = React . createRef < HostInstance > ( ) ;
288+ const targetRef = React . createRef < HostInstance > ( ) ;
297289
298- function TestComponent ( { showPortal } : { showPortal : boolean } ) {
290+ function TestComponent ( { showPortal} : { showPortal : boolean } ) {
299291 React . useLayoutEffect ( ( ) => {
300292 if ( targetRef . current ) {
301293 targetTag = getTargetTag ( targetRef ) ;
@@ -306,10 +298,7 @@ describe('Portal', () => {
306298 < View nativeID = "root" >
307299 < View >
308300 { showPortal && targetTag != null
309- ? createPortal (
310- < View nativeID = "portaled-child" /> ,
311- targetTag ,
312- )
301+ ? createPortal ( < View nativeID = "portaled-child" /> , targetTag )
313302 : null }
314303 </ View >
315304 < View ref = { targetRef } nativeID = "target" collapsable = { false } />
@@ -323,24 +312,22 @@ describe('Portal', () => {
323312
324313 const withPortal = {
325314 type : 'View' ,
326- props : { nativeID : 'root' } ,
315+ props : { nativeID : 'root' } ,
327316 children : [
328317 {
329318 type : 'View' ,
330- props : { nativeID : 'target' } ,
319+ props : { nativeID : 'target' } ,
331320 children : [
332- { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
321+ { type : 'View' , props : { nativeID : 'portaled-child' } , children : [ ] } ,
333322 ] ,
334323 } ,
335324 ] ,
336325 } ;
337326
338327 const withoutPortal = {
339328 type : 'View' ,
340- props : { nativeID : 'root' } ,
341- children : [
342- { type : 'View' , props : { nativeID : 'target' } , children : [ ] } ,
343- ] ,
329+ props : { nativeID : 'root' } ,
330+ children : [ { type : 'View' , props : { nativeID : 'target' } , children : [ ] } ] ,
344331 } ;
345332
346333 // mount
0 commit comments