Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions packages/@react-aria/virtualizer/src/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement

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

let onScrollTimeout = useCallback(() => {
state.isScrolling = false;
setScrolling(false);
state.scrollTimeout = null;

window.dispatchEvent(new Event('tk.connect-observer'));
onScrollEnd?.();
}, [state, onScrollEnd]);

let onScroll = useCallback((e) => {
if (e.target !== e.currentTarget) {
return;
Expand Down Expand Up @@ -128,21 +119,29 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
// keep track of the current timeout time and only reschedule
// the timer when it is getting close.
let now = Date.now();
if (!('onscrollend' in window) && state.scrollEndTime <= now + 50) {
if (state.scrollEndTime <= now + 50) {
state.scrollEndTime = now + 300;

if (state.scrollTimeout != null) {
clearTimeout(state.scrollTimeout);
}

state.scrollTimeout = setTimeout(onScrollTimeout, 300);
state.scrollTimeout = setTimeout(() => {
state.isScrolling = false;
setScrolling(false);
state.scrollTimeout = null;

window.dispatchEvent(new Event('tk.connect-observer'));
if (onScrollEnd) {
onScrollEnd();
}
}, 300);
}
});
}, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollTimeout]);
}, [props, direction, state, contentSize, onVisibleRectChange, onScrollStart, onScrollEnd]);

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

useEffect(() => {
return () => {
Expand Down