Test only use longpress for iOS

This commit is contained in:
Lim Chee Aun 2023-10-01 17:14:32 +08:00
parent d05f0a4f23
commit a364488895

View file

@ -789,19 +789,29 @@ function Status({
x: 0, x: 0,
y: 0, y: 0,
}); });
const isIOS =
window.ontouchstart !== undefined &&
/iPad|iPhone|iPod/.test(navigator.userAgent);
// Only iOS/iPadOS browsers don't support contextmenu
// Some comments report iPadOS might support contextmenu if a mouse is connected
const bindLongPressContext = useLongPress( const bindLongPressContext = useLongPress(
(e) => { isIOS
const { clientX, clientY } = e.touches?.[0] || e; ? (e) => {
// link detection copied from onContextMenu because here it works if (e.pointerType === 'mouse') return;
const link = e.target.closest('a'); // There's 'pen' too, but not sure if contextmenu event would trigger from a pen
if (link && /^https?:\/\//.test(link.getAttribute('href'))) return;
e.preventDefault(); const { clientX, clientY } = e.touches?.[0] || e;
setContextMenuAnchorPoint({ // link detection copied from onContextMenu because here it works
x: clientX, const link = e.target.closest('a');
y: clientY, if (link && /^https?:\/\//.test(link.getAttribute('href'))) return;
}); e.preventDefault();
setIsContextMenuOpen(true); setContextMenuAnchorPoint({
}, x: clientX,
y: clientY,
});
setIsContextMenuOpen(true);
}
: null,
{ {
threshold: 600, threshold: 600,
captureEvent: true, captureEvent: true,