Message Context Menu: Fix auto-closing for PWA on iOS 15 (#1481)

This commit is contained in:
Alexander Zinchuk 2021-10-08 16:17:22 +03:00
parent 325d168931
commit 66f1cb1b37

View File

@ -2,7 +2,9 @@ import { RefObject } from 'react';
import { useState, useEffect, useCallback } from '../lib/teact/teact';
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;
@ -11,6 +13,12 @@ function checkIsDisabledForMobile() {
&& window.document.body.classList.contains('enable-symbol-menu-transforms');
}
function stopEvent(e: Event) {
e.stopImmediatePropagation();
e.preventDefault();
e.stopPropagation();
}
export default (
elementRef: RefObject<HTMLElement>,
isMenuDisabled?: boolean,
@ -80,14 +88,20 @@ export default (
return;
}
// temporarily intercept and clear the next click
// Temporarily intercept and clear the next click
element.addEventListener('touchend', function cancelClickOnce(e) {
element.removeEventListener('touchend', cancelClickOnce, true);
e.stopImmediatePropagation();
e.preventDefault();
e.stopPropagation();
stopEvent(e);
}, 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');
setIsContextMenuOpen(true);
setContextMenuPosition({ x: clientX, y: clientY });