mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
attempt to fix ios long press detection
This commit is contained in:
1 parent
730dadffd0
commit
8a7bd507e2
3 files changed
+35
-1
No files matched your search
@@ -131,6 +131,7 @@ export type MessageProps = {
|
||||
};
|
||||
|
||||
import { useMenuAnchor } from '$hooks/useMenuAnchor';
|
||||
import { shouldIgnoreMessageLongPress } from './messageTouch';
|
||||
|
||||
const clamp = (str: string, len: number) => (str.length > len ? `${str.slice(0, len)}...` : str);
|
||||
|
||||
@@ -988,7 +989,7 @@ function MessageInternal(
|
||||
onContextMenu={contextMenuHandler}
|
||||
onTouchStart={(evt) => {
|
||||
const target = evt.target instanceof Element ? evt.target : undefined;
|
||||
if (target?.closest('[data-gestures="ignore"]')) {
|
||||
if (shouldIgnoreMessageLongPress(target)) {
|
||||
menu.triggerProps.onTouchCancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { shouldIgnoreMessageLongPress } from './messageTouch';
|
||||
|
||||
describe('shouldIgnoreMessageLongPress', () => {
|
||||
it('keeps the message swipe wrapper eligible for long press', () => {
|
||||
const swipeWrapper = document.createElement('div');
|
||||
swipeWrapper.dataset.gestures = 'ignore';
|
||||
swipeWrapper.dataset.messageSwipe = '';
|
||||
const messageContent = document.createElement('span');
|
||||
swipeWrapper.append(messageContent);
|
||||
|
||||
expect(shouldIgnoreMessageLongPress(messageContent)).toBe(false);
|
||||
});
|
||||
|
||||
it('still ignores nested controls that own touch gestures', () => {
|
||||
const swipeWrapper = document.createElement('div');
|
||||
swipeWrapper.dataset.gestures = 'ignore';
|
||||
swipeWrapper.dataset.messageSwipe = '';
|
||||
const media = document.createElement('div');
|
||||
media.dataset.gestures = 'ignore';
|
||||
const mediaContent = document.createElement('img');
|
||||
media.append(mediaContent);
|
||||
swipeWrapper.append(media);
|
||||
|
||||
expect(shouldIgnoreMessageLongPress(mediaContent)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
const IGNORED_MESSAGE_GESTURE_SELECTOR =
|
||||
'[data-gestures="ignore"]:not([data-message-swipe])';
|
||||
|
||||
export function shouldIgnoreMessageLongPress(target: Element | null | undefined): boolean {
|
||||
return target?.closest(IGNORED_MESSAGE_GESTURE_SELECTOR) !== null;
|
||||
}
|
||||
Reference in new issue
Block a user