Skip to content

Commit

Permalink
Fixes swipedown listener (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbrembeck committed Feb 19, 2023
1 parent ad94214 commit 48b7f1e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/elements/modalwrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ const ModalWrapper: React.FC<ModalProps> = ({ children, id, buttonType, buttonCl
};

const handleTouchStart = (event: TouchEvent) => {
const touchY = event.changedTouches[0].clientY;
const swipeThreshold = 50;
const touchStartY = event.touches[0].clientY;
let touchEndY;

document.body.addEventListener("touchmove", handleTouchMove);
document.body.addEventListener("touchend", handleTouchEnd);

function handleTouchMove(event: TouchEvent) {
const currentY = event.changedTouches[0].clientY;
const deltaY = currentY - touchY;
if (deltaY > swipeThreshold) {
function handleTouchEnd(event: TouchEvent) {
touchEndY = event.changedTouches[0].clientY;
if (touchEndY - touchStartY > 50) {
closeModal();
document.body.removeEventListener("touchmove", handleTouchMove);
}
document.body.removeEventListener("touchend", handleTouchEnd);
document.removeEventListener("touchstart", handleTouchStart);
}
};


document.addEventListener("keydown", handleEscapeKeyPress);
document.addEventListener("touchstart", handleTouchStart);
Expand Down

0 comments on commit 48b7f1e

Please sign in to comment.