@@ -70,15 +70,17 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
70
70
} = props ;
71
71
72
72
// ================================= MISC =================================
73
- const inVirtual =
74
- virtual !== false && height && itemHeight && data && itemHeight * data . length > height ;
73
+ const useVirtual = ! ! ( virtual !== false && height && itemHeight ) ;
74
+ const inVirtual = useVirtual && data && itemHeight * data . length > height ;
75
75
76
76
const [ scrollTop , setScrollTop ] = useState ( 0 ) ;
77
77
const [ scrollMoving , setScrollMoving ] = useState ( false ) ;
78
78
79
79
const mergedClassName = classNames ( prefixCls , className ) ;
80
80
const mergedData = data || EMPTY_DATA ;
81
81
const componentRef = useRef < HTMLDivElement > ( ) ;
82
+ const fillerInnerRef = useRef < HTMLDivElement > ( ) ;
83
+ const scrollBarRef = useRef < any > ( ) ; // Hack on scrollbar to enable flash call
82
84
83
85
// =============================== Item Key ===============================
84
86
const getKey = React . useCallback < GetKey < T > > (
@@ -129,7 +131,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
129
131
130
132
// ========================== Visible Calculation =========================
131
133
const { scrollHeight, start, end, offset } = React . useMemo ( ( ) => {
132
- if ( ! inVirtual ) {
134
+ if ( ! useVirtual ) {
133
135
return {
134
136
scrollHeight : undefined ,
135
137
start : 0 ,
@@ -138,6 +140,16 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
138
140
} ;
139
141
}
140
142
143
+ // Always use virtual scroll bar in avoid shaking
144
+ if ( ! inVirtual ) {
145
+ return {
146
+ scrollHeight : fillerInnerRef . current ?. offsetHeight || 0 ,
147
+ start : 0 ,
148
+ end : mergedData . length - 1 ,
149
+ offset : undefined ,
150
+ } ;
151
+ }
152
+
141
153
let itemTop = 0 ;
142
154
let startIndex : number ;
143
155
let startOffset : number ;
@@ -184,7 +196,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
184
196
end : endIndex ,
185
197
offset : startOffset ,
186
198
} ;
187
- } , [ inVirtual , scrollTop , mergedData , heightUpdatedMark , height ] ) ;
199
+ } , [ inVirtual , useVirtual , scrollTop , mergedData , heightUpdatedMark , height ] ) ;
188
200
189
201
rangeRef . current . start = start ;
190
202
rangeRef . current . end = end ;
@@ -227,7 +239,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
227
239
228
240
// Since this added in global,should use ref to keep update
229
241
const [ onRawWheel , onFireFoxScroll ] = useFrameWheel (
230
- inVirtual ,
242
+ useVirtual ,
231
243
isScrollAtTop ,
232
244
isScrollAtBottom ,
233
245
offsetY => {
@@ -239,7 +251,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
239
251
) ;
240
252
241
253
// Mobile touch move
242
- useMobileTouchMove ( inVirtual , componentRef , ( deltaY , smoothOffset ) => {
254
+ useMobileTouchMove ( useVirtual , componentRef , ( deltaY , smoothOffset ) => {
243
255
if ( originScroll ( deltaY , smoothOffset ) ) {
244
256
return false ;
245
257
}
@@ -251,7 +263,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
251
263
React . useLayoutEffect ( ( ) => {
252
264
// Firefox only
253
265
function onMozMousePixelScroll ( e : Event ) {
254
- if ( inVirtual ) {
266
+ if ( useVirtual ) {
255
267
e . preventDefault ( ) ;
256
268
}
257
269
}
@@ -265,7 +277,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
265
277
componentRef . current . removeEventListener ( 'DOMMouseScroll' , onFireFoxScroll as any ) ;
266
278
componentRef . current . removeEventListener ( 'MozMousePixelScroll' , onMozMousePixelScroll as any ) ;
267
279
} ;
268
- } , [ inVirtual ] ) ;
280
+ } , [ useVirtual ] ) ;
269
281
270
282
// ================================= Ref ==================================
271
283
const scrollTo = useScrollTo < T > (
@@ -276,6 +288,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
276
288
getKey ,
277
289
collectHeight ,
278
290
syncScrollTop ,
291
+ ( ) => {
292
+ scrollBarRef . current ?. delayHidden ( ) ;
293
+ } ,
279
294
) ;
280
295
281
296
React . useImperativeHandle ( ref , ( ) => ( {
@@ -289,7 +304,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
289
304
if ( height ) {
290
305
componentStyle = { [ fullHeight ? 'height' : 'maxHeight' ] : height , ...ScrollStyle } ;
291
306
292
- if ( inVirtual ) {
307
+ if ( useVirtual ) {
293
308
componentStyle . overflowY = 'hidden' ;
294
309
295
310
if ( scrollMoving ) {
@@ -318,13 +333,15 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
318
333
height = { scrollHeight }
319
334
offset = { offset }
320
335
onInnerResize = { collectHeight }
336
+ ref = { fillerInnerRef }
321
337
>
322
338
{ listChildren }
323
339
</ Filler >
324
340
</ Component >
325
341
326
- { inVirtual && (
342
+ { useVirtual && (
327
343
< ScrollBar
344
+ ref = { scrollBarRef }
328
345
prefixCls = { prefixCls }
329
346
scrollTop = { scrollTop }
330
347
height = { height }
0 commit comments