diff --git a/src/app/features/room-nav/RoomNavItem.tsx b/src/app/features/room-nav/RoomNavItem.tsx index 306469dd0..5bedaf635 100644 --- a/src/app/features/room-nav/RoomNavItem.tsx +++ b/src/app/features/room-nav/RoomNavItem.tsx @@ -354,10 +354,10 @@ export function RoomNavItem({ const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const { - onPointerDown, - onPointerUp, - onPointerMove, - onPointerCancel, + onTouchStart, + onTouchEnd, + onTouchMove, + onTouchCancel, firedRef: longPressFiredRef, isPressing, } = useMobileLongPress(() => { @@ -457,11 +457,13 @@ export function RoomNavItem({ marginTop: hideText ? toRem(5) : '0', userSelect: 'none', WebkitUserSelect: 'none', + WebkitTouchCallout: 'none', + WebkitTapHighlightColor: 'transparent', }} - onPointerDown={onPointerDown} - onPointerUp={onPointerUp} - onPointerMove={onPointerMove} - onPointerCancel={onPointerCancel} + onTouchStart={onTouchStart} + onTouchEnd={onTouchEnd} + onTouchMove={onTouchMove} + onTouchCancel={onTouchCancel} > { @@ -935,12 +935,16 @@ function MessageInternal( )}
void, delay = 500) { startX.current = null; }, []); - const onPointerDown = useCallback( - (e: React.PointerEvent | PointerEvent) => { - if (e.pointerType !== 'touch') return; + const onTouchStart = useCallback( + (e: React.TouchEvent | TouchEvent) => { firedRef.current = false; setIsPressing(true); - startY.current = e.clientY; - startX.current = e.clientX; - + if ('touches' in e && e.touches[0]) { + startY.current = e.touches[0].clientY; + startX.current = e.touches[0].clientX; + } + timerRef.current = setTimeout(() => { firedRef.current = true; callback(); @@ -36,18 +37,18 @@ export function useMobileLongPress(callback: () => void, delay = 500) { [callback, delay] ); - const onPointerUp = useCallback(() => { + const onTouchEnd = useCallback(() => { clear(); }, [clear]); - const onPointerMove = useCallback( - (e: React.PointerEvent | PointerEvent) => { - if (startY.current === null || startX.current === null || e.pointerType !== 'touch') { + const onTouchMove = useCallback( + (e: React.TouchEvent | TouchEvent) => { + if (startY.current === null || startX.current === null || !('touches' in e) || !e.touches[0]) { clear(); return; } - const diffY = Math.abs(e.clientY - startY.current); - const diffX = Math.abs(e.clientX - startX.current); + const diffY = Math.abs(e.touches[0].clientY - startY.current); + const diffX = Math.abs(e.touches[0].clientX - startX.current); if (diffY > 10 || diffX > 10) { clear(); @@ -55,8 +56,8 @@ export function useMobileLongPress(callback: () => void, delay = 500) { }, [clear] ); + + const onTouchCancel = useCallback(() => clear(), [clear]); - const onPointerCancel = useCallback(() => clear(), [clear]); - - return { onPointerDown, onPointerUp, onPointerMove, onPointerCancel, firedRef, isPressing }; + return { onTouchStart, onTouchEnd, onTouchMove, onTouchCancel, firedRef, isPressing }; }