@@ -57,6 +57,7 @@ React.forwardRef(ScrollView);
57
57
export { ScrollViewForwardRef as ScrollView } ;
58
58
59
59
interface ScrollViewAria {
60
+ isScrolling : boolean ,
60
61
scrollViewProps : HTMLAttributes < HTMLElement > ,
61
62
contentProps : HTMLAttributes < HTMLElement >
62
63
}
@@ -84,6 +85,16 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
84
85
let { direction} = useLocale ( ) ;
85
86
86
87
let [ isScrolling , setScrolling ] = useState ( false ) ;
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
+
87
98
let onScroll = useCallback ( ( e ) => {
88
99
if ( e . target !== e . currentTarget ) {
89
100
return ;
@@ -117,30 +128,21 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
117
128
// keep track of the current timeout time and only reschedule
118
129
// the timer when it is getting close.
119
130
let now = Date . now ( ) ;
120
- if ( state . scrollEndTime <= now + 50 ) {
131
+ if ( ! ( 'onscrollend' in window ) && state . scrollEndTime <= now + 50 ) {
121
132
state . scrollEndTime = now + 300 ;
122
133
123
134
if ( state . scrollTimeout != null ) {
124
135
clearTimeout ( state . scrollTimeout ) ;
125
136
}
126
137
127
- state . scrollTimeout = setTimeout ( ( ) => {
128
- state . isScrolling = false ;
129
- setScrolling ( false ) ;
130
- state . scrollTimeout = null ;
131
-
132
- window . dispatchEvent ( new Event ( 'tk.connect-observer' ) ) ;
133
- if ( onScrollEnd ) {
134
- onScrollEnd ( ) ;
135
- }
136
- } , 300 ) ;
138
+ state . scrollTimeout = setTimeout ( onScrollTimeout , 300 ) ;
137
139
}
138
140
} ) ;
139
- } , [ props , direction , state , contentSize , onVisibleRectChange , onScrollStart , onScrollEnd ] ) ;
141
+ } , [ props , direction , state , contentSize , onVisibleRectChange , onScrollStart , onScrollTimeout ] ) ;
140
142
141
143
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
142
144
useEvent ( ref , 'scroll' , onScroll ) ;
143
-
145
+ useEvent ( ref , 'scrollend' , onScrollTimeout ) ;
144
146
145
147
useEffect ( ( ) => {
146
148
return ( ) => {
@@ -265,6 +267,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
265
267
} ;
266
268
267
269
return {
270
+ isScrolling,
268
271
scrollViewProps : {
269
272
...otherProps ,
270
273
style
0 commit comments