@@ -8,13 +8,23 @@ import { skipFrames } from './utils/skipFrames'
88
99import type { FlatIndexLocationWithAlign } from './interfaces'
1010
11- export function getInitialTopMostItemIndexNumber ( location : FlatIndexLocationWithAlign | number , totalCount : number ) : number {
11+ export type InitialTopMostItemIndexLocation = FlatIndexLocationWithAlign | number | undefined
12+
13+ export function getInitialTopMostItemIndexNumber ( location : InitialTopMostItemIndexLocation , totalCount : number ) : number {
14+ if ( location === undefined ) {
15+ return 0
16+ }
17+
1218 const lastIndex = totalCount - 1
1319 const index = typeof location === 'number' ? location : location . index === 'LAST' ? lastIndex : location . index
1420 return Math . max ( 0 , Math . min ( index , lastIndex ) )
1521}
1622
17- export function initialTopMostItemIndexIsZero ( location : FlatIndexLocationWithAlign | number ) : boolean {
23+ export function initialTopMostItemIndexIsZero ( location : InitialTopMostItemIndexLocation ) : boolean {
24+ if ( location === undefined ) {
25+ return true
26+ }
27+
1828 if ( typeof location === 'number' ) {
1929 return location === 0
2030 }
@@ -29,7 +39,7 @@ export function initialTopMostItemIndexIsZero(location: FlatIndexLocationWithAli
2939export const initialTopMostItemIndexSystem = u . system (
3040 ( [ { defaultItemSize, listRefresh, sizes } , { scrollTop } , { scrollTargetReached, scrollToIndex } , { didMount } ] ) => {
3141 const scrolledToInitialItem = u . statefulStream ( true )
32- const initialTopMostItemIndex = u . statefulStream < FlatIndexLocationWithAlign | number > ( 0 )
42+ const initialTopMostItemIndex = u . statefulStream < InitialTopMostItemIndexLocation > ( 0 )
3343 const initialItemFinalLocationReached = u . statefulStream ( true )
3444
3545 u . connect (
@@ -61,6 +71,12 @@ export const initialTopMostItemIndexSystem = u.system(
6171 u . withLatestFrom ( initialTopMostItemIndex )
6272 ) ,
6373 ( [ , initialTopMostItemIndex ] ) => {
74+ if ( initialTopMostItemIndex === undefined ) {
75+ u . publish ( scrolledToInitialItem , true )
76+ u . publish ( initialItemFinalLocationReached , true )
77+ return
78+ }
79+
6480 u . handleNext ( scrollTargetReached , ( ) => {
6581 u . publish ( initialItemFinalLocationReached , true )
6682 } )
0 commit comments