Skip to content

Commit 02cc874

Browse files
authored
revert: use timeout to determine scroll end (#8929)
1 parent 4314a1e commit 02cc874

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

packages/@react-aria/virtualizer/src/ScrollView.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
8686

8787
let [isScrolling, setScrolling] = useState(false);
8888

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-
9889
let onScroll = useCallback((e) => {
9990
if (e.target !== e.currentTarget) {
10091
return;
@@ -128,21 +119,29 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
128119
// keep track of the current timeout time and only reschedule
129120
// the timer when it is getting close.
130121
let now = Date.now();
131-
if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
122+
if (state.scrollEndTime <= now + 50) {
132123
state.scrollEndTime = now + 300;
133124

134125
if (state.scrollTimeout != null) {
135126
clearTimeout(state.scrollTimeout);
136127
}
137128

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);
139139
}
140140
});
141-
}, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollTimeout]);
141+
}, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);
142142

143143
// Attach event directly to ref so RAC Virtualizer doesn't need to send props upward.
144144
useEvent(ref, 'scroll', onScroll);
145-
useEvent(ref, 'scrollend', onScrollTimeout);
146145

147146
useEffect(() => {
148147
return () => {

0 commit comments

Comments
 (0)