Skip to content

Commit

Permalink
fix: 스와이프 문제
Browse files Browse the repository at this point in the history
  • Loading branch information
junghaesung79 committed Jul 13, 2024
1 parent bb03e36 commit caed3bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/layout/Header/MobilePanel/MobilePanel.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
&--show {
transform: translateX(0);
}

&--transition-prevented {
transition: none;
}
}

&__user {
Expand Down
58 changes: 29 additions & 29 deletions src/layout/Header/MobilePanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

import { useLocation, useNavigate } from 'react-router-dom';

Expand Down Expand Up @@ -55,59 +55,58 @@ export default function MobilePanel() {
const { isMobile } = useMediaQuery();
const { user } = useCoopMe();
const { logout } = useLogout();
const [transitionPrevented, setTransitionPrevented] = useState(false);

const {
isMenuOpen: isMobileMenuOpen,
openMenu,
closeMenu,
isMenuOpen: isMobileMenuOpen, openMenu, closeMenu,
} = useMobileMenu(pathname, isMobile);

const handleMenuClick = () => {
if (!isMobileMenuOpen) {
window.history.pushState({ menuOpen: true }, '');
}
window.history.pushState({ menuOpen: true }, '');
openMenu();
setTimeout(() => setTransitionPrevented(true), 300);
};

const handleMenuClose = () => {
setTransitionPrevented(false);
closeMenu();
};

useEffect(() => {
const handlePopState = (event: PopStateEvent) => {
if (isMobileMenuOpen) {
event.preventDefault();
closeMenu();
setTimeout(() => setTransitionPrevented(false), 300);
}
};

window.addEventListener('popstate', handlePopState);

return () => {
window.removeEventListener('popstate', handlePopState);
};
return () => window.removeEventListener('popstate', handlePopState);
}, [isMobileMenuOpen, closeMenu]);

useEffect(() => {
document.body.style.cssText = `
overflow: hidden;`;

return () => {
document.body.style.cssText = '';
};
}, []);

useEffect(() => {
window.addEventListener('keydown', (event) => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && isMobileMenuOpen) {
closeMenu();
}
});
};

window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [isMobileMenuOpen, closeMenu]);

useEffect(() => {
if (isMobileMenuOpen) {
document.body.style.cssText = 'overflow: hidden;';
} else {
document.body.style.cssText = '';
}

return () => {
window.removeEventListener('keydown', (event) => {
if (event.key === 'Escape' && isMobileMenuOpen) {
closeMenu();
}
});
document.body.style.cssText = '';
};
}, [isMobileMenuOpen, closeMenu]);
}, [isMobileMenuOpen]);

return (
<>
Expand Down Expand Up @@ -142,14 +141,15 @@ export default function MobilePanel() {
[styles['mobile-header__panel']]: true,
[styles['mobile-header__panel--logged-in']]: true,
[styles['mobile-header__panel--show']]: isMobileMenuOpen,
[styles['mobile-header__panel--transition-prevented']]: transitionPrevented,
})}
>
<div className={styles['mobile-header__user']}>
<button
type="button"
aria-label="뒤로 가기 버튼"
className={styles['mobile-header__backspace']}
onClick={closeMenu}
onClick={handleMenuClose}
>
<BackArrowIcon title="뒤로 가기 버튼" />
</button>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Coop/components/ConfirmModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default function ConfirmModal({
confirm,
}: ConfirmModalProps) {
useEffect(() => {
document.body.style.cssText = `
overflow: hidden;`;
document.body.style.cssText = 'overflow: hidden;';

return () => {
document.body.style.cssText = '';
Expand Down

0 comments on commit caed3bd

Please sign in to comment.