feat: pull to close modal window
This commit is contained in:
1 parent
5f5a7b9d87
commit
a903752f9d
3 files changed
+116
-23
No files matched your search
@@ -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;
|
||||
}
|
||||
}, [])
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user