@@ -37,6 +37,10 @@ export type VirtualListProps<ITEM> = {
37
37
* Minimum distance for triggering a calculation when scrolling.
38
38
*/
39
39
triggerDistance ?: number ,
40
+ /**
41
+ * listen to scroll event.
42
+ */
43
+ onScroll : typeof document . onscroll ,
40
44
className ?: string ,
41
45
style ?: React . CSSProperties ,
42
46
} & OptionalKeys < typeof defaultProps >
@@ -124,21 +128,21 @@ export const VirtualList = forwardRef(function <ITEM>(
124
128
}
125
129
} , [ props . itemSize , props . items , forceRerender ] ) ;
126
130
//
127
- const handleScroll = ( ) => {
131
+ const handleScroll = function ( event : unknown ) {
128
132
if ( ignoreScrollOnce . current ) {
129
133
ignoreScrollOnce . current = false
130
134
return
131
135
}
132
136
setlistSize ( list . current ! . clientHeight )
133
137
const scrollTop2 = list . current ! . scrollTop
134
138
if ( Math . abs ( prevScrollTop . current - scrollTop2 ) > ( props . triggerDistance ?? itemSize ) ) {
135
- console . log ( 'triggerd' ) ;
136
-
137
139
setscrollTop ( scrollTop2 )
138
140
prevScrollTop . current = scrollTop2
139
141
} else if ( scrollToIndexRef . current ) {
140
142
setforceRerender ( [ ] )
141
143
}
144
+ // @ts -ignore
145
+ props . onScroll ?. call ( this , event )
142
146
}
143
147
//
144
148
useImperativeHandle ( ref , ( ) => ( {
@@ -151,7 +155,7 @@ export const VirtualList = forwardRef(function <ITEM>(
151
155
} ,
152
156
forceUpdate ( ) {
153
157
setforceRerender ( [ ] )
154
- }
158
+ } ,
155
159
} ) , [ itemSize ] ) ;
156
160
useLayoutEffect ( ( ) => {
157
161
if ( scrollToIndexRef . current ) {
@@ -175,4 +179,4 @@ export const VirtualList = forwardRef(function <ITEM>(
175
179
} )
176
180
177
181
// @ts -ignore
178
- VirtualList . defaultProps = defaultProps
182
+ VirtualList . defaultProps = defaultProps
0 commit comments