Skip to content

Commit

Permalink
feat: #27 useBottomSheet Hook 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
imb96 committed Oct 29, 2023
1 parent afcf152 commit 72d69f3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/hooks/useBottomSheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useCallback, useRef } from 'react';

export const useBottomSheet = (closeModal: () => void) => {
const record = useRef({
first: 0,
move: 0,
});

const handleTouchStart = (event: TouchEvent) => {
record.current.first = event.touches[0].screenY;
};

const handleTouchMove = useCallback((event: TouchEvent) => {
if (!record.current.move) {
record.current.move = event.touches[0].screenY;
}
}, []);

const handleTouchEnd = () => {
if (record.current.first !== null && record.current.move !== null) {
if (record.current.first < record.current.move) {
closeModal();
}
}
record.current.first = 0;
record.current.move = 0;
};

return { handleTouchStart, handleTouchMove, handleTouchEnd };
};

0 comments on commit 72d69f3

Please sign in to comment.