diff --git a/src/engine/Graphics2d.module.css b/src/engine/Graphics2d.module.css index 03f0db87..82a72dfd 100644 --- a/src/engine/Graphics2d.module.css +++ b/src/engine/Graphics2d.module.css @@ -4,7 +4,7 @@ */ .wrapperStyles { - width: 100%; + width: 100%; height: 100vh; justify-content: center; overflow: scroll; diff --git a/src/ui/Main.module.css b/src/ui/Main.module.css index 82e87451..b85fb5f4 100644 --- a/src/ui/Main.module.css +++ b/src/ui/Main.module.css @@ -79,6 +79,7 @@ right: 0; bottom: 0; z-index: 1; + user-select: none; } .settings { diff --git a/src/ui/MobileSettings/MobileSettings.jsx b/src/ui/MobileSettings/MobileSettings.jsx index 8f76ec95..48df9bf6 100644 --- a/src/ui/MobileSettings/MobileSettings.jsx +++ b/src/ui/MobileSettings/MobileSettings.jsx @@ -11,13 +11,15 @@ export const MobileSettings = () => { const [is2DMenuOpen, setIs2DMenuOpen] = useState(false); const [isCursorMenuOpen, setIsCursorMenuOpen] = useState(false); const [isSmallScreen, setIsSmallScreen] = useState(window.matchMedia('(max-width: 767px)').matches); + const [isMenuHidden, setIsMenuHidden] = useState(false); + const containerRef = useRef(null); + const pressTimer = useRef(null); const toggleSettingsMenu = () => { setIsSettingsMenuOpen(!isSettingsMenuOpen); setIs2DMenuOpen(false); setIsCursorMenuOpen(false); }; - const toggle2DMenu = () => { setIs2DMenuOpen(!is2DMenuOpen); setIsSettingsMenuOpen(false); @@ -28,37 +30,49 @@ export const MobileSettings = () => { setIsSettingsMenuOpen(false); setIs2DMenuOpen(false); }; + const closeAllMenu = () => { + setIsSettingsMenuOpen(false); + setIs2DMenuOpen(false); + setIsCursorMenuOpen(false); + }; + useEffect(() => { - const handleResize = () => { - setIsSmallScreen(window.matchMedia('(max-width: 768px)').matches); + const onLongPress = () => { + setIsMenuHidden((current) => !current); + closeAllMenu(); }; - window.addEventListener('resize', handleResize); + const startPress = () => { + pressTimer.current = setTimeout(() => { + onLongPress(); + }, 1000); + }; + + const endPress = () => { + clearTimeout(pressTimer.current); + }; + + document.addEventListener('touchstart', startPress); + document.addEventListener('touchend', endPress); return () => { - window.removeEventListener('resize', handleResize); + document.removeEventListener('touchstart', startPress); + document.removeEventListener('touchend', endPress); }; }, []); - useEffect(() => { - //TODO: next step is implementation behavior - const handleClickOutside = (event) => { - if (containerRef.current && !containerRef.current.contains(event.target)) { - setIsSettingsMenuOpen(false); - setIs2DMenuOpen(false); - setIsCursorMenuOpen(false); - } + const handleResize = () => { + setIsSmallScreen(window.matchMedia('(max-width: 768px)').matches); }; - const containerElement = containerRef.current; - containerElement.addEventListener('click', handleClickOutside); + window.addEventListener('resize', handleResize); return () => { - containerElement.removeEventListener('click', handleClickOutside); + window.removeEventListener('resize', handleResize); }; }, []); return ( -