@@ -113,9 +113,28 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
113
113
...restProps
114
114
} = props ;
115
115
116
+ // =============================== Item Key ===============================
117
+ const getKey = React . useCallback < GetKey < T > > (
118
+ ( item : T ) => {
119
+ if ( typeof itemKey === 'function' ) {
120
+ return itemKey ( item ) ;
121
+ }
122
+ return item ?. [ itemKey as string ] ;
123
+ } ,
124
+ [ itemKey ] ,
125
+ ) ;
126
+
127
+ // ================================ Height ================================
128
+ const [ setInstanceRef , collectHeight , heights , heightUpdatedMark ] = useHeights (
129
+ getKey ,
130
+ null ,
131
+ null ,
132
+ ) ;
133
+
116
134
// ================================= MISC =================================
117
135
const useVirtual = ! ! ( virtual !== false && height && itemHeight ) ;
118
- const inVirtual = useVirtual && data && ( itemHeight * data . length > height || ! ! scrollWidth ) ;
136
+ const containerHeight = React . useMemo ( ( ) => Object . values ( heights . maps ) . reduce ( ( total , curr ) => total + curr , 0 ) , [ heights . id , heights . maps ] ) ;
137
+ const inVirtual = useVirtual && data && ( Math . max ( itemHeight * data . length , containerHeight ) > height || ! ! scrollWidth ) ;
119
138
const isRTL = direction === 'rtl' ;
120
139
121
140
const mergedClassName = classNames ( prefixCls , { [ `${ prefixCls } -rtl` ] : isRTL } , className ) ;
@@ -136,17 +155,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
136
155
setScrollMoving ( false ) ;
137
156
} ;
138
157
139
- // =============================== Item Key ===============================
140
- const getKey = React . useCallback < GetKey < T > > (
141
- ( item : T ) => {
142
- if ( typeof itemKey === 'function' ) {
143
- return itemKey ( item ) ;
144
- }
145
- return item ?. [ itemKey as string ] ;
146
- } ,
147
- [ itemKey ] ,
148
- ) ;
149
-
150
158
const sharedConfig : SharedConfig < T > = {
151
159
getKey,
152
160
} ;
@@ -176,13 +184,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
176
184
const [ diffItem ] = useDiffItem ( mergedData , getKey ) ;
177
185
diffItemRef . current = diffItem ;
178
186
179
- // ================================ Height ================================
180
- const [ setInstanceRef , collectHeight , heights , heightUpdatedMark ] = useHeights (
181
- getKey ,
182
- null ,
183
- null ,
184
- ) ;
185
-
186
187
// ========================== Visible Calculation =========================
187
188
const {
188
189
scrollHeight,
@@ -307,6 +308,8 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
307
308
const getVirtualScrollInfo = ( ) => ( {
308
309
x : isRTL ? - offsetLeft : offsetLeft ,
309
310
y : offsetTop ,
311
+ maxScrollWidth : ! ! scrollWidth ? scrollWidth - size . width : 0 ,
312
+ maxScrollHeight : scrollHeight > height ? maxScrollHeight : 0 ,
310
313
} ) ;
311
314
312
315
const lastVirtualScrollInfoRef = useRef ( getVirtualScrollInfo ( ) ) ;
@@ -354,7 +357,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
354
357
355
358
const keepInHorizontalRange = ( nextOffsetLeft : number ) => {
356
359
let tmpOffsetLeft = nextOffsetLeft ;
357
- const max = scrollWidth - size . width ;
360
+ const max = ! ! scrollWidth ? scrollWidth - size . width : 0 ;
358
361
tmpOffsetLeft = Math . max ( tmpOffsetLeft , 0 ) ;
359
362
tmpOffsetLeft = Math . min ( tmpOffsetLeft , max ) ;
360
363
0 commit comments