mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix: ios mobile modals
This commit is contained in:
1 parent
3f05165b54
commit
d9d9e52989
3 files changed
+39
-32
No files matched your search
@@ -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}
|
||||
>
|
||||
<NavItem
|
||||
variant="Background"
|
||||
|
||||
@@ -834,10 +834,10 @@ function MessageInternal(
|
||||
};
|
||||
|
||||
const {
|
||||
onPointerDown,
|
||||
onPointerUp,
|
||||
onPointerMove,
|
||||
onPointerCancel,
|
||||
onTouchStart,
|
||||
onTouchEnd,
|
||||
onTouchMove,
|
||||
onTouchCancel,
|
||||
firedRef: longPressFiredRef,
|
||||
isPressing,
|
||||
} = useMobileLongPress(() => {
|
||||
@@ -935,12 +935,16 @@ function MessageInternal(
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{ width: '100%' }}
|
||||
style={{
|
||||
width: '100%',
|
||||
WebkitTouchCallout: 'none',
|
||||
WebkitTapHighlightColor: 'transparent',
|
||||
}}
|
||||
onContextMenu={handleContextMenu}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerUp={onPointerUp}
|
||||
onPointerMove={onPointerMove}
|
||||
onPointerCancel={onPointerCancel}
|
||||
onTouchStart={onTouchStart}
|
||||
onTouchEnd={onTouchEnd}
|
||||
onTouchMove={onTouchMove}
|
||||
onTouchCancel={onTouchCancel}
|
||||
>
|
||||
<WrappedMessage
|
||||
headerJSX={headerJSX(collapse)}
|
||||
|
||||
@@ -19,14 +19,15 @@ export function useMobileLongPress(callback: () => 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 };
|
||||
}
|
||||
Reference in new issue
Block a user