@@ -450,29 +450,31 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
450
450
const { isVirtual } = this . state ;
451
451
const { height, itemHeight, data } = this . props ;
452
452
const { index, align = 'auto' } = arg0 ;
453
- const itemCount = Math . ceil ( height / itemHeight ) ;
453
+ const visibleCount = Math . ceil ( height / itemHeight ) ;
454
454
const item = data [ index ] ;
455
455
if ( item ) {
456
456
const { clientHeight } = this . listRef . current ;
457
457
458
458
if ( isVirtual ) {
459
459
// Calculate related data
460
- const { itemIndex, itemOffsetPtg, startIndex, endIndex } = this . state ;
460
+ const { itemIndex, itemOffsetPtg } = this . state ;
461
+ const { scrollTop } = this . listRef . current ;
462
+ const scrollPtg = getElementScrollPercentage ( this . listRef . current ) ;
461
463
462
464
const relativeLocatedItemTop = getItemRelativeTop ( {
463
465
itemIndex,
464
466
itemOffsetPtg,
465
467
itemElementHeights : this . itemElementHeights ,
466
- scrollPtg : getElementScrollPercentage ( this . listRef . current ) ,
468
+ scrollPtg,
467
469
clientHeight,
468
470
getItemKey : this . getIndexKey ,
469
471
} ) ;
470
472
471
473
// We will force render related items to collect height for re-location
472
474
this . setState (
473
475
{
474
- startIndex : Math . max ( 0 , index - itemCount ) ,
475
- endIndex : Math . min ( data . length - 1 , index + itemCount ) ,
476
+ startIndex : Math . max ( 0 , index - visibleCount ) ,
477
+ endIndex : Math . min ( data . length - 1 , index + visibleCount ) ,
476
478
} ,
477
479
( ) => {
478
480
this . collectItemHeights ( ) ;
@@ -485,7 +487,7 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
485
487
let shouldChange = true ;
486
488
487
489
// Check if exist in the visible range
488
- if ( Math . abs ( itemIndex - index ) < itemCount ) {
490
+ if ( Math . abs ( itemIndex - index ) < visibleCount ) {
489
491
let itemTop = relativeLocatedItemTop ;
490
492
if ( index < itemIndex ) {
491
493
for ( let i = index ; i < itemIndex ; i += 1 ) {
@@ -506,7 +508,17 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
506
508
// Out of range will fall back to position align
507
509
mergedAlgin = index < itemIndex ? 'top' : 'bottom' ;
508
510
} else {
511
+ const {
512
+ itemIndex : nextIndex ,
513
+ itemOffsetPtg : newOffsetPtg ,
514
+ startIndex,
515
+ endIndex,
516
+ } = getRangeIndex ( scrollPtg , data . length , visibleCount ) ;
517
+
509
518
this . setState ( {
519
+ scrollTop,
520
+ itemIndex : nextIndex ,
521
+ itemOffsetPtg : newOffsetPtg ,
510
522
startIndex,
511
523
endIndex,
512
524
} ) ;
0 commit comments