Message Context Menu: Fix click-through on iOS PWA (#2521)
This commit is contained in:
parent
f0574f78a5
commit
5f54b1610d
@ -7,6 +7,7 @@ import {
|
|||||||
} from '../util/environment';
|
} from '../util/environment';
|
||||||
|
|
||||||
const LONG_TAP_DURATION_MS = 200;
|
const LONG_TAP_DURATION_MS = 200;
|
||||||
|
const IOS_PWA_CONTEXT_MENU_DELAY_MS = 100;
|
||||||
|
|
||||||
function stopEvent(e: Event) {
|
function stopEvent(e: Event) {
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
@ -83,17 +84,34 @@ const useContextMenuHandlers = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Temporarily intercept and clear the next click
|
// Temporarily intercept and clear the next click
|
||||||
element.addEventListener('touchend', function cancelClickOnce(e) {
|
element.addEventListener('touchend', (e) => {
|
||||||
element.removeEventListener('touchend', cancelClickOnce, true);
|
// On iOS in PWA mode, the context menu may cause click-through to the element in the menu upon opening
|
||||||
|
if (IS_IOS && IS_PWA) {
|
||||||
|
setTimeout(() => {
|
||||||
|
element.removeEventListener('mousedown', stopEvent, {
|
||||||
|
capture: true,
|
||||||
|
});
|
||||||
|
element.removeEventListener('click', stopEvent, {
|
||||||
|
capture: true,
|
||||||
|
});
|
||||||
|
}, IOS_PWA_CONTEXT_MENU_DELAY_MS);
|
||||||
|
}
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
}, true);
|
}, {
|
||||||
|
once: true,
|
||||||
|
capture: true,
|
||||||
|
});
|
||||||
|
|
||||||
// On iOS15, in PWA mode, the context menu immediately closes after opening
|
// On iOS15, in PWA mode, the context menu immediately closes after opening
|
||||||
if (IS_PWA && IS_IOS) {
|
if (IS_PWA && IS_IOS) {
|
||||||
element.addEventListener('mousedown', function cancelClickOnce(e) {
|
element.addEventListener('mousedown', stopEvent, {
|
||||||
element.removeEventListener('mousedown', cancelClickOnce, true);
|
once: true,
|
||||||
stopEvent(e);
|
capture: true,
|
||||||
}, true);
|
});
|
||||||
|
element.addEventListener('click', stopEvent, {
|
||||||
|
once: true,
|
||||||
|
capture: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsContextMenuOpen(true);
|
setIsContextMenuOpen(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user