@@ -20,6 +20,7 @@ import useOriginScroll from './hooks/useOriginScroll';
20
20
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect' ;
21
21
import { getSpinSize } from './utils/scrollbarUtil' ;
22
22
import { useEvent } from 'rc-util' ;
23
+ import { useGetSize } from './hooks/useGetSize' ;
23
24
24
25
const EMPTY_DATA = [ ] ;
25
26
@@ -261,14 +262,14 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
261
262
const verticalScrollBarRef = useRef < ScrollBarRef > ( ) ;
262
263
const horizontalScrollBarRef = useRef < ScrollBarRef > ( ) ;
263
264
264
- const horizontalScrollBarSpinSize = React . useMemo ( ( ) => getSpinSize ( size . width , scrollWidth ) , [
265
- size . width ,
266
- scrollWidth ,
267
- ] ) ;
268
- const verticalScrollBarSpinSize = React . useMemo ( ( ) => getSpinSize ( size . height , scrollHeight ) , [
269
- size . height ,
270
- scrollHeight ,
271
- ] ) ;
265
+ const horizontalScrollBarSpinSize = React . useMemo (
266
+ ( ) => getSpinSize ( size . width , scrollWidth ) ,
267
+ [ size . width , scrollWidth ] ,
268
+ ) ;
269
+ const verticalScrollBarSpinSize = React . useMemo (
270
+ ( ) => getSpinSize ( size . height , scrollHeight ) ,
271
+ [ size . height , scrollHeight ] ,
272
+ ) ;
272
273
273
274
// =============================== In Range ===============================
274
275
const maxScrollHeight = scrollHeight - height ;
@@ -456,31 +457,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
456
457
} , [ start , end , mergedData ] ) ;
457
458
458
459
// ================================ Extra =================================
459
- const getSize = ( startKey : React . Key , endKey = startKey ) => {
460
- let top = 0 ;
461
- let bottom = 0 ;
462
- let total = 0 ;
463
-
464
- const dataLen = mergedData . length ;
465
- for ( let i = 0 ; i < dataLen ; i += 1 ) {
466
- const item = mergedData [ i ] ;
467
- const key = getKey ( item ) ;
468
-
469
- const cacheHeight = heights . get ( key ) ?? itemHeight ;
470
- bottom = total + cacheHeight ;
471
-
472
- if ( key === startKey ) {
473
- top = total ;
474
- }
475
- if ( key === endKey ) {
476
- break ;
477
- }
478
-
479
- total = bottom ;
480
- }
481
-
482
- return { top, bottom } ;
483
- } ;
460
+ const getSize = useGetSize ( mergedData , getKey , heights , itemHeight ) ;
484
461
485
462
const extraContent = extraRender ?.( {
486
463
start,
0 commit comments