feat: pull to close modal window

This commit is contained in:
ner committed 2024-04-03 20:20:12 +03:00
1 parent 5f5a7b9d87
commit a903752f9d
3 files changed
+116 -23

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
import { useCallback, useRef } from 'react';
export default function useScrollDelta() {
const lastKnownScrollPosition = useRef(0);
const deltaY = useRef(0);
return {
delta: deltaY,
onScroll: useCallback((scroll: React.UIEvent<HTMLDivElement, UIEvent>) => {
let ticking = false;
if (!ticking) {
window.requestAnimationFrame(() => {
const top = (scroll.target as HTMLDivElement).scrollTop;
deltaY.current = top - lastKnownScrollPosition.current;
lastKnownScrollPosition.current = top;
ticking = false;
});
ticking = true;
}
}, [])
};
}