@@ -13,7 +13,6 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
1313import type { HostInstance } from 'react-native' ;
1414
1515import * as Fantom from '@react-native/fantom' ;
16- import nullthrows from 'nullthrows' ;
1716import * as React from 'react' ;
1817import { createRef } from 'react' ;
1918import { ScrollView , View } from 'react-native' ;
@@ -86,10 +85,7 @@ test('maintainVisibleContentPosition preserves position on prepend', () => {
8685 expect ( scrollLogs1 . length ) . toBeGreaterThan ( 0 ) ;
8786
8887 // Prepend 5 items at the top
89- const itemsAfterPrepend = [
90- ...makeItems ( 5 , NUM_ITEMS ) ,
91- ...initialItems ,
92- ] ;
88+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
9389
9490 Fantom . runTask ( ( ) => {
9591 root . render (
@@ -278,10 +274,7 @@ test('maintainVisibleContentPosition with autoscrollToTopThreshold triggers scro
278274 expect ( logs . length ) . toBeGreaterThan ( 0 ) ;
279275
280276 // Prepend items — since we're within the threshold, scroll should go to top
281- const itemsAfterPrepend = [
282- ...makeItems ( 5 , NUM_ITEMS ) ,
283- ...items ,
284- ] ;
277+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...items ] ;
285278
286279 Fantom . runTask ( ( ) => {
287280 root . render (
@@ -338,10 +331,7 @@ test('maintainVisibleContentPosition with minIndexForVisible > 0 skips early ite
338331
339332 // Prepend 3 items — item 8 becomes item 11, but minIndexForVisible: 5
340333 // means items 0-4 are not considered for anchor
341- const itemsAfterPrepend = [
342- ...makeItems ( 3 , NUM_ITEMS ) ,
343- ...items ,
344- ] ;
334+ const itemsAfterPrepend = [ ...makeItems ( 3 , NUM_ITEMS ) , ...items ] ;
345335
346336 Fantom . runTask ( ( ) => {
347337 root . render (
@@ -397,10 +387,7 @@ test('maintainVisibleContentPosition with inverted ScrollView preserves position
397387 expect ( scrollLogs1 . length ) . toBeGreaterThan ( 0 ) ;
398388
399389 // Prepend 5 items at the top
400- const itemsAfterPrepend = [
401- ...makeItems ( 5 , NUM_ITEMS ) ,
402- ...initialItems ,
403- ] ;
390+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
404391
405392 Fantom . runTask ( ( ) => {
406393 root . render (
@@ -531,10 +518,7 @@ test('maintainVisibleContentPosition does not interrupt scroll during prepend',
531518 expect ( dragScrollLogs . length ) . toBeGreaterThan ( 0 ) ;
532519
533520 // Prepend 5 items while the scroll position is at item 10
534- const itemsAfterPrepend = [
535- ...makeItems ( 5 , NUM_ITEMS ) ,
536- ...initialItems ,
537- ] ;
521+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
538522
539523 Fantom . runTask ( ( ) => {
540524 root . render (
@@ -589,10 +573,7 @@ test('maintainVisibleContentPosition preserves position on horizontal prepend',
589573 root . takeMountingManagerLogs ( ) ;
590574
591575 // Prepend 5 items
592- const itemsAfterPrepend = [
593- ...makeItems ( 5 , NUM_ITEMS ) ,
594- ...initialItems ,
595- ] ;
576+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
596577
597578 Fantom . runTask ( ( ) => {
598579 root . render (
@@ -644,10 +625,7 @@ test('maintainVisibleContentPosition preserves position on horizontal + inverted
644625
645626 root . takeMountingManagerLogs ( ) ;
646627
647- const itemsAfterPrepend = [
648- ...makeItems ( 5 , NUM_ITEMS ) ,
649- ...initialItems ,
650- ] ;
628+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
651629
652630 Fantom . runTask ( ( ) => {
653631 root . render (
@@ -700,10 +678,7 @@ test('maintainVisibleContentPosition does not trigger correction on append', ()
700678 root . takeMountingManagerLogs ( ) ;
701679
702680 // Append 5 items at the end (should not affect anchor position)
703- const itemsAfterAppend = [
704- ...initialItems ,
705- ...makeItems ( 5 , NUM_ITEMS ) ,
706- ] ;
681+ const itemsAfterAppend = [ ...initialItems , ...makeItems ( 5 , NUM_ITEMS ) ] ;
707682
708683 Fantom . runTask ( ( ) => {
709684 root . render (
@@ -916,23 +891,23 @@ test('maintainVisibleContentPosition handles sibling items above anchor growing'
916891 style = { { height : VIEWPORT_HEIGHT , width : 100 } }
917892 maintainVisibleContentPosition = { { minIndexForVisible : 0 } } >
918893 { initialItems . map ( ( item , index ) =>
919- index < 5
920- ? (
921- < View
922- key = { item . key }
923- nativeID = { `item_ ${ item . id } ` }
924- style = { { height : ITEM_HEIGHT * 2 , width : 100 } } >
925- < View
926- nativeID = { `inner_ ${ item . id } ` }
927- style = { {
928- height : ITEM_HEIGHT * 2 - 2 ,
929- width : 100 - 2 ,
930- backgroundColor : '#4CAF50' ,
931- } }
932- / >
933- </ View >
934- )
935- : renderItem ( item ) ,
894+ index < 5 ? (
895+ < View
896+ key = { item . key }
897+ nativeID = { `item_ ${ item . id } ` }
898+ style = { { height : ITEM_HEIGHT * 2 , width : 100 } } >
899+ < View
900+ nativeID = { `inner_ ${ item . id } ` }
901+ style = { {
902+ height : ITEM_HEIGHT * 2 - 2 ,
903+ width : 100 - 2 ,
904+ backgroundColor : '#4CAF50' ,
905+ } }
906+ />
907+ </ View >
908+ ) : (
909+ renderItem ( item )
910+ ) ,
936911 ) }
937912 </ ScrollView > ,
938913 ) ;
@@ -983,23 +958,23 @@ test('maintainVisibleContentPosition handles sibling items above anchor shrinkin
983958 style = { { height : VIEWPORT_HEIGHT , width : 100 } }
984959 maintainVisibleContentPosition = { { minIndexForVisible : 0 } } >
985960 { initialItems . map ( ( item , index ) =>
986- index < 5
987- ? (
988- < View
989- key = { item . key }
990- nativeID = { `item_ ${ item . id } ` }
991- style = { { height : ITEM_HEIGHT / 2 , width : 100 } } >
992- < View
993- nativeID = { `inner_ ${ item . id } ` }
994- style = { {
995- height : ITEM_HEIGHT / 2 - 2 ,
996- width : 100 - 2 ,
997- backgroundColor : '#4CAF50' ,
998- } }
999- / >
1000- </ View >
1001- )
1002- : renderItem ( item ) ,
961+ index < 5 ? (
962+ < View
963+ key = { item . key }
964+ nativeID = { `item_ ${ item . id } ` }
965+ style = { { height : ITEM_HEIGHT / 2 , width : 100 } } >
966+ < View
967+ nativeID = { `inner_ ${ item . id } ` }
968+ style = { {
969+ height : ITEM_HEIGHT / 2 - 2 ,
970+ width : 100 - 2 ,
971+ backgroundColor : '#4CAF50' ,
972+ } }
973+ />
974+ </ View >
975+ ) : (
976+ renderItem ( item )
977+ ) ,
1003978 ) }
1004979 </ ScrollView > ,
1005980 ) ;
@@ -1093,10 +1068,7 @@ test('maintainVisibleContentPosition with initialScrollIndex + prepend after rem
10931068 root . takeMountingManagerLogs ( ) ;
10941069
10951070 // Force remount with a different key (simulates navigation to new screen with same component)
1096- const itemsAfterPrepend = [
1097- ...makeItems ( 3 , NUM_ITEMS ) ,
1098- ...initialItems ,
1099- ] ;
1071+ const itemsAfterPrepend = [ ...makeItems ( 3 , NUM_ITEMS ) , ...initialItems ] ;
11001072
11011073 Fantom . runTask ( ( ) => {
11021074 root . render (
@@ -1152,10 +1124,7 @@ test('maintainVisibleContentPosition preserves position on horizontal prepend in
11521124 root . takeMountingManagerLogs ( ) ;
11531125
11541126 // Prepend 5 items in RTL mode
1155- const itemsAfterPrepend = [
1156- ...makeItems ( 5 , NUM_ITEMS ) ,
1157- ...initialItems ,
1158- ] ;
1127+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
11591128
11601129 Fantom . runTask ( ( ) => {
11611130 root . render (
@@ -1281,10 +1250,7 @@ test('maintainVisibleContentPosition with getItemLayout prop', () => {
12811250 root . takeMountingManagerLogs ( ) ;
12821251
12831252 // Prepend 4 items
1284- const itemsAfterPrepend = [
1285- ...makeItems ( 4 , NUM_ITEMS ) ,
1286- ...initialItems ,
1287- ] ;
1253+ const itemsAfterPrepend = [ ...makeItems ( 4 , NUM_ITEMS ) , ...initialItems ] ;
12881254
12891255 const getItemLayoutAfterPrepend = ( _ : mixed , index : number ) => ( {
12901256 length : ITEM_HEIGHT ,
@@ -1361,10 +1327,7 @@ test('maintainVisibleContentPosition handles all items culled (spacers only in v
13611327
13621328 // Prepend 3 items — the culled items (0-2) are replaced by new items (20-22)
13631329 // The viewport may show spacers (culled item slots) and new data items
1364- const itemsAfterPrepend = [
1365- ...makeItems ( 3 , NUM_ITEMS ) ,
1366- ...initialItems ,
1367- ] ;
1330+ const itemsAfterPrepend = [ ...makeItems ( 3 , NUM_ITEMS ) , ...initialItems ] ;
13681331
13691332 Fantom . runTask ( ( ) => {
13701333 root . render (
@@ -1439,10 +1402,7 @@ test('maintainVisibleContentPosition simulates pull-to-refresh pattern', () => {
14391402 root . takeMountingManagerLogs ( ) ;
14401403
14411404 // Refresh completes: prepend new items (simulating fresh data from server)
1442- const itemsAfterRefresh = [
1443- ...makeItems ( 3 , NUM_ITEMS ) ,
1444- ...currentItems ,
1445- ] ;
1405+ const itemsAfterRefresh = [ ...makeItems ( 3 , NUM_ITEMS ) , ...currentItems ] ;
14461406
14471407 Fantom . runTask ( ( ) => {
14481408 root . render (
@@ -1497,9 +1457,7 @@ test('maintainVisibleContentPosition handles unmount/remount (navigation pattern
14971457
14981458 // Unmount: replace with empty content (simulates navigating away)
14991459 Fantom . runTask ( ( ) => {
1500- root . render (
1501- < View style = { { height : VIEWPORT_HEIGHT , width : 100 } } /> ,
1502- ) ;
1460+ root . render ( < View style = { { height : VIEWPORT_HEIGHT , width : 100 } } /> ) ;
15031461 } ) ;
15041462
15051463 const unmountLogs = root . takeMountingManagerLogs ( ) ;
@@ -1559,10 +1517,7 @@ test('maintainVisibleContentPosition handles contentInset changes (keyboard/safe
15591517 root . takeMountingManagerLogs ( ) ;
15601518
15611519 // Simulate keyboard appearance: change contentInset (bottom inset increases)
1562- const itemsAfterPrepend = [
1563- ...makeItems ( 2 , NUM_ITEMS ) ,
1564- ...initialItems ,
1565- ] ;
1520+ const itemsAfterPrepend = [ ...makeItems ( 2 , NUM_ITEMS ) , ...initialItems ] ;
15661521
15671522 Fantom . runTask ( ( ) => {
15681523 root . render (
@@ -1672,10 +1627,7 @@ test('maintainVisibleContentPosition handles large prepend (50+ items)', () => {
16721627 root . takeMountingManagerLogs ( ) ;
16731628
16741629 // Prepend 50 items — this causes view recycling, tag comparison safeguard must detect it
1675- const itemsAfterPrepend = [
1676- ...makeItems ( 50 , NUM_ITEMS ) ,
1677- ...initialItems ,
1678- ] ;
1630+ const itemsAfterPrepend = [ ...makeItems ( 50 , NUM_ITEMS ) , ...initialItems ] ;
16791631
16801632 Fantom . runTask ( ( ) => {
16811633 root . render (
@@ -1722,10 +1674,7 @@ test('maintainVisibleContentPosition handles first prepend after initial mount',
17221674 expect ( initialLogs . length ) . toBeGreaterThan ( 0 ) ;
17231675
17241676 // Prepend 5 items on the very first update (anchor state being initialized)
1725- const itemsAfterPrepend = [
1726- ...makeItems ( 5 , NUM_ITEMS ) ,
1727- ...initialItems ,
1728- ] ;
1677+ const itemsAfterPrepend = [ ...makeItems ( 5 , NUM_ITEMS ) , ...initialItems ] ;
17291678
17301679 Fantom . runTask ( ( ) => {
17311680 root . render (
@@ -1768,7 +1717,10 @@ test('maintainVisibleContentPosition handles variable-height items', () => {
17681717 < View
17691718 key = { item . key }
17701719 nativeID = { `item_${ item . id } ` }
1771- style = { { height : index % 3 === 0 ? ITEM_HEIGHT * 2 : ITEM_HEIGHT , width : 100 } } >
1720+ style = { {
1721+ height : index % 3 === 0 ? ITEM_HEIGHT * 2 : ITEM_HEIGHT ,
1722+ width : 100 ,
1723+ } } >
17721724 < View
17731725 nativeID = { `inner_${ item . id } ` }
17741726 style = { {
@@ -1794,10 +1746,7 @@ test('maintainVisibleContentPosition handles variable-height items', () => {
17941746 root . takeMountingManagerLogs ( ) ;
17951747
17961748 // Prepend 3 variable-height items
1797- const itemsAfterPrepend = [
1798- ...makeItems ( 3 , NUM_ITEMS ) ,
1799- ...initialItems ,
1800- ] ;
1749+ const itemsAfterPrepend = [ ...makeItems ( 3 , NUM_ITEMS ) , ...initialItems ] ;
18011750
18021751 Fantom . runTask ( ( ) => {
18031752 root . render (
@@ -1809,7 +1758,10 @@ test('maintainVisibleContentPosition handles variable-height items', () => {
18091758 < View
18101759 key = { item . key }
18111760 nativeID = { `item_${ item . id } ` }
1812- style = { { height : index % 3 === 0 ? ITEM_HEIGHT * 2 : ITEM_HEIGHT , width : 100 } } >
1761+ style = { {
1762+ height : index % 3 === 0 ? ITEM_HEIGHT * 2 : ITEM_HEIGHT ,
1763+ width : 100 ,
1764+ } } >
18131765 < View
18141766 nativeID = { `inner_${ item . id } ` }
18151767 style = { {
@@ -1864,10 +1816,7 @@ test('maintainVisibleContentPosition handles anchor culled (pushed off-screen)',
18641816 root . takeMountingManagerLogs ( ) ;
18651817
18661818 // Prepend 10 items — pushes item_3 off-screen (culled), a new anchor is selected
1867- const itemsAfterPrepend = [
1868- ...makeItems ( 10 , NUM_ITEMS ) ,
1869- ...initialItems ,
1870- ] ;
1819+ const itemsAfterPrepend = [ ...makeItems ( 10 , NUM_ITEMS ) , ...initialItems ] ;
18711820
18721821 Fantom . runTask ( ( ) => {
18731822 root . render (
@@ -1920,10 +1869,7 @@ test('maintainVisibleContentPosition with inverted + recycling', () => {
19201869 root . takeMountingManagerLogs ( ) ;
19211870
19221871 // Prepend 50 items — causes recycling in inverted mode
1923- const itemsAfterPrepend = [
1924- ...makeItems ( 50 , NUM_ITEMS ) ,
1925- ...initialItems ,
1926- ] ;
1872+ const itemsAfterPrepend = [ ...makeItems ( 50 , NUM_ITEMS ) , ...initialItems ] ;
19271873
19281874 Fantom . runTask ( ( ) => {
19291875 root . render (
0 commit comments