@@ -86,15 +86,6 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
86
86
87
87
let [ isScrolling , setScrolling ] = useState ( false ) ;
88
88
89
- let onScrollTimeout = useCallback ( ( ) => {
90
- state . isScrolling = false ;
91
- setScrolling ( false ) ;
92
- state . scrollTimeout = null ;
93
-
94
- window . dispatchEvent ( new Event ( 'tk.connect-observer' ) ) ;
95
- onScrollEnd ?.( ) ;
96
- } , [ state , onScrollEnd ] ) ;
97
-
98
89
let onScroll = useCallback ( ( e ) => {
99
90
if ( e . target !== e . currentTarget ) {
100
91
return ;
@@ -128,21 +119,29 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
128
119
// keep track of the current timeout time and only reschedule
129
120
// the timer when it is getting close.
130
121
let now = Date . now ( ) ;
131
- if ( ! ( 'onscrollend' in window ) && state . scrollEndTime <= now + 50 ) {
122
+ if ( state . scrollEndTime <= now + 50 ) {
132
123
state . scrollEndTime = now + 300 ;
133
124
134
125
if ( state . scrollTimeout != null ) {
135
126
clearTimeout ( state . scrollTimeout ) ;
136
127
}
137
128
138
- state . scrollTimeout = setTimeout ( onScrollTimeout , 300 ) ;
129
+ state . scrollTimeout = setTimeout ( ( ) => {
130
+ state . isScrolling = false ;
131
+ setScrolling ( false ) ;
132
+ state . scrollTimeout = null ;
133
+
134
+ window . dispatchEvent ( new Event ( 'tk.connect-observer' ) ) ;
135
+ if ( onScrollEnd ) {
136
+ onScrollEnd ( ) ;
137
+ }
138
+ } , 300 ) ;
139
139
}
140
140
} ) ;
141
- } , [ props , direction , state , contentSize , onVisibleRectChange , onScrollStart , onScrollTimeout ] ) ;
141
+ } , [ props , direction , state , contentSize , onVisibleRectChange , onScrollStart , onScrollEnd ] ) ;
142
142
143
143
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
144
144
useEvent ( ref , 'scroll' , onScroll ) ;
145
- useEvent ( ref , 'scrollend' , onScrollTimeout ) ;
146
145
147
146
useEffect ( ( ) => {
148
147
return ( ) => {
0 commit comments