Message Context Menu: Fix auto-closing for PWA on iOS 15 (#1481)
This commit is contained in:
parent
325d168931
commit
66f1cb1b37
@ -2,7 +2,9 @@ import { RefObject } from 'react';
|
|||||||
import { useState, useEffect, useCallback } from '../lib/teact/teact';
|
import { useState, useEffect, useCallback } from '../lib/teact/teact';
|
||||||
|
|
||||||
import { IAnchorPosition } from '../types';
|
import { IAnchorPosition } from '../types';
|
||||||
import { IS_TOUCH_ENV, IS_SINGLE_COLUMN_LAYOUT } from '../util/environment';
|
import {
|
||||||
|
IS_TOUCH_ENV, IS_SINGLE_COLUMN_LAYOUT, IS_PWA, IS_IOS,
|
||||||
|
} from '../util/environment';
|
||||||
|
|
||||||
const LONG_TAP_DURATION_MS = 200;
|
const LONG_TAP_DURATION_MS = 200;
|
||||||
|
|
||||||
@ -11,6 +13,12 @@ function checkIsDisabledForMobile() {
|
|||||||
&& window.document.body.classList.contains('enable-symbol-menu-transforms');
|
&& window.document.body.classList.contains('enable-symbol-menu-transforms');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopEvent(e: Event) {
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
export default (
|
export default (
|
||||||
elementRef: RefObject<HTMLElement>,
|
elementRef: RefObject<HTMLElement>,
|
||||||
isMenuDisabled?: boolean,
|
isMenuDisabled?: boolean,
|
||||||
@ -80,14 +88,20 @@ export default (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporarily intercept and clear the next click
|
// Temporarily intercept and clear the next click
|
||||||
element.addEventListener('touchend', function cancelClickOnce(e) {
|
element.addEventListener('touchend', function cancelClickOnce(e) {
|
||||||
element.removeEventListener('touchend', cancelClickOnce, true);
|
element.removeEventListener('touchend', cancelClickOnce, true);
|
||||||
e.stopImmediatePropagation();
|
stopEvent(e);
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
// On iOS15, in PWA mode, the context menu immediately closes after opening
|
||||||
|
if (IS_PWA && IS_IOS) {
|
||||||
|
element.addEventListener('mousedown', function cancelClickOnce(e) {
|
||||||
|
element.removeEventListener('mousedown', cancelClickOnce, true);
|
||||||
|
stopEvent(e);
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
document.body.classList.add('no-selection');
|
document.body.classList.add('no-selection');
|
||||||
setIsContextMenuOpen(true);
|
setIsContextMenuOpen(true);
|
||||||
setContextMenuPosition({ x: clientX, y: clientY });
|
setContextMenuPosition({ x: clientX, y: clientY });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user