mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-04-24 11:57:52 +00:00
prevent menu if user scrolls
This commit is contained in:
parent
481542baf6
commit
77ad4c78be
@ -24,14 +24,21 @@ const CustomStyledMenu = styled(Menu)(({ theme }) => ({
|
|||||||
|
|
||||||
export const GlobalTouchMenu = () => {
|
export const GlobalTouchMenu = () => {
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
const [menuPosition, setMenuPosition] = useState(null);
|
||||||
|
const [lastEnteredGroupId] = useRecoilState(lastEnteredGroupIdAtom);
|
||||||
|
|
||||||
|
// Refs for tap tracking and scroll detection
|
||||||
const tapCount = useRef(0);
|
const tapCount = useRef(0);
|
||||||
const lastTapTime = useRef(0);
|
const lastTapTime = useRef(0);
|
||||||
const [menuPosition, setMenuPosition] = useState(null);
|
const touchStartY = useRef(0);
|
||||||
const [lastEnteredGroupId] = useRecoilState(lastEnteredGroupIdAtom)
|
const touchMoved = useRef(false);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleTouchStart = (event) => {
|
const handleTouchStart = (event) => {
|
||||||
|
// Reset scroll flag and store the starting Y position
|
||||||
|
touchMoved.current = false;
|
||||||
|
touchStartY.current = event.touches[0].clientY;
|
||||||
|
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const tapGap = currentTime - lastTapTime.current;
|
const tapGap = currentTime - lastTapTime.current;
|
||||||
const { clientX, clientY } = event.touches[0];
|
const { clientX, clientY } = event.touches[0];
|
||||||
@ -41,23 +48,35 @@ export const GlobalTouchMenu = () => {
|
|||||||
} else {
|
} else {
|
||||||
tapCount.current = 1; // Reset if too much time has passed
|
tapCount.current = 1; // Reset if too much time has passed
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTapTime.current = currentTime;
|
lastTapTime.current = currentTime;
|
||||||
|
|
||||||
if (tapCount.current === 3) {
|
if (tapCount.current === 3 && !touchMoved.current) {
|
||||||
setMenuPosition({
|
setMenuPosition({ top: clientY, left: clientX });
|
||||||
top: clientY,
|
|
||||||
left: clientX,
|
|
||||||
});
|
|
||||||
setMenuOpen(true);
|
setMenuOpen(true);
|
||||||
tapCount.current = 0; // Reset after activation
|
tapCount.current = 0; // Reset after activation
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTouchMove = (event) => {
|
||||||
|
const currentY = event.touches[0].clientY;
|
||||||
|
// If the vertical movement exceeds 10px, consider it a scroll
|
||||||
|
if (Math.abs(currentY - touchStartY.current) > 10) {
|
||||||
|
touchMoved.current = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTouchEnd = () => {
|
||||||
|
// You can optionally reset tapCount here if needed
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('touchstart', handleTouchStart);
|
document.addEventListener('touchstart', handleTouchStart);
|
||||||
|
document.addEventListener('touchmove', handleTouchMove);
|
||||||
|
document.addEventListener('touchend', handleTouchEnd);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('touchstart', handleTouchStart);
|
document.removeEventListener('touchstart', handleTouchStart);
|
||||||
|
document.removeEventListener('touchmove', handleTouchMove);
|
||||||
|
document.removeEventListener('touchend', handleTouchEnd);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -69,55 +88,57 @@ export const GlobalTouchMenu = () => {
|
|||||||
<CustomStyledMenu
|
<CustomStyledMenu
|
||||||
open={menuOpen}
|
open={menuOpen}
|
||||||
anchorReference="anchorPosition"
|
anchorReference="anchorPosition"
|
||||||
anchorPosition={menuPosition ? { top: menuPosition?.top, left: menuPosition?.left } : undefined}
|
anchorPosition={
|
||||||
|
menuPosition ? { top: menuPosition.top, left: menuPosition.left } : undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={handleClose}>
|
<MenuItem onClick={handleClose}>
|
||||||
<Box sx={{
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: '10px'
|
|
||||||
}}>
|
|
||||||
<CloseIcon />
|
<CloseIcon />
|
||||||
<Typography variant="inherit">Close Menu</Typography>
|
<Typography variant="inherit">Close Menu</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
<MenuItem onClick={()=> {
|
<MenuItem
|
||||||
executeEvent('open-apps-mode', {})
|
onClick={() => {
|
||||||
handleClose()
|
executeEvent('open-apps-mode', {});
|
||||||
}}>
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Typography variant="inherit">Apps</Typography>
|
<Typography variant="inherit">Apps</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem onClick={()=> {
|
<MenuItem
|
||||||
executeEvent("openGroupMessage", {
|
onClick={() => {
|
||||||
from: lastEnteredGroupId ,
|
executeEvent('openGroupMessage', { from: lastEnteredGroupId });
|
||||||
});
|
handleClose();
|
||||||
handleClose()
|
}}
|
||||||
}}>
|
>
|
||||||
<Typography variant="inherit">Group Chat</Typography>
|
<Typography variant="inherit">Group Chat</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem onClick={()=> {
|
<MenuItem
|
||||||
executeEvent('openUserLookupDrawer', {
|
onClick={() => {
|
||||||
addressOrName: ""
|
executeEvent('openUserLookupDrawer', { addressOrName: '' });
|
||||||
})
|
handleClose();
|
||||||
handleClose()
|
}}
|
||||||
}}>
|
>
|
||||||
<Typography variant="inherit">User Lookup</Typography>
|
<Typography variant="inherit">User Lookup</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem onClick={()=> {
|
<MenuItem
|
||||||
executeEvent('openUserProfile',{})
|
onClick={() => {
|
||||||
handleClose()
|
executeEvent('openUserProfile', {});
|
||||||
}}>
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Typography variant="inherit">My Account</Typography>
|
<Typography variant="inherit">My Account</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem onClick={()=> {
|
<MenuItem
|
||||||
executeEvent('openWalletsApp', {})
|
onClick={() => {
|
||||||
handleClose()
|
executeEvent('openWalletsApp', {});
|
||||||
}}>
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Typography variant="inherit">Wallets</Typography>
|
<Typography variant="inherit">Wallets</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</CustomStyledMenu>
|
</CustomStyledMenu>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user