mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
Message Context Menu: Fix flickering (#1646)
This commit is contained in:
parent
fc0365d5b9
commit
8f1b32cdb4
@ -11,6 +11,7 @@ import useContextMenuPosition from '../../../hooks/useContextMenuPosition';
|
|||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
import useFlag from '../../../hooks/useFlag';
|
import useFlag from '../../../hooks/useFlag';
|
||||||
|
import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment';
|
||||||
|
|
||||||
import Menu from '../../ui/Menu';
|
import Menu from '../../ui/Menu';
|
||||||
import MenuItem from '../../ui/MenuItem';
|
import MenuItem from '../../ui/MenuItem';
|
||||||
@ -159,6 +160,13 @@ const MessageContextMenu: FC<OwnProps> = ({
|
|||||||
}, ANIMATION_DURATION);
|
}, ANIMATION_DURATION);
|
||||||
}, [isOpen, markIsReady, unmarkIsReady]);
|
}, [isOpen, markIsReady, unmarkIsReady]);
|
||||||
|
|
||||||
|
const extraHeightAudioPlayer = (IS_SINGLE_COLUMN_LAYOUT
|
||||||
|
&& (document.querySelector<HTMLElement>('.AudioPlayer-content'))?.offsetHeight) || 0;
|
||||||
|
const pinnedElement = document.querySelector<HTMLElement>('.HeaderPinnedMessage-wrapper');
|
||||||
|
const extraHeightPinned = (((IS_SINGLE_COLUMN_LAYOUT && !extraHeightAudioPlayer)
|
||||||
|
|| (!IS_SINGLE_COLUMN_LAYOUT && pinnedElement?.classList.contains('full-width')))
|
||||||
|
&& pinnedElement?.offsetHeight) || 0;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
positionX, positionY, style, menuStyle, withScroll,
|
positionX, positionY, style, menuStyle, withScroll,
|
||||||
} = useContextMenuPosition(
|
} = useContextMenuPosition(
|
||||||
@ -167,8 +175,9 @@ const MessageContextMenu: FC<OwnProps> = ({
|
|||||||
getRootElement,
|
getRootElement,
|
||||||
getMenuElement,
|
getMenuElement,
|
||||||
SCROLLBAR_WIDTH,
|
SCROLLBAR_WIDTH,
|
||||||
(document.querySelector('.MiddleHeader') as HTMLElement).offsetHeight,
|
(document.querySelector<HTMLElement>('.MiddleHeader')!).offsetHeight,
|
||||||
withReactions ? REACTION_BUBBLE_EXTRA_WIDTH : undefined,
|
withReactions ? REACTION_BUBBLE_EXTRA_WIDTH : undefined,
|
||||||
|
extraHeightPinned + extraHeightAudioPlayer,
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect } from '../lib/teact/teact';
|
import { useState, useLayoutEffect } from '../lib/teact/teact';
|
||||||
import { IAnchorPosition } from '../types';
|
import { IAnchorPosition } from '../types';
|
||||||
|
|
||||||
const MENU_POSITION_VISUAL_COMFORT_SPACE_PX = 16;
|
const MENU_POSITION_VISUAL_COMFORT_SPACE_PX = 16;
|
||||||
@ -12,6 +12,7 @@ export default (
|
|||||||
extraPaddingX = 0,
|
extraPaddingX = 0,
|
||||||
extraTopPadding = 0,
|
extraTopPadding = 0,
|
||||||
marginSides = 0,
|
marginSides = 0,
|
||||||
|
extraMarginTop = 0,
|
||||||
) => {
|
) => {
|
||||||
const [positionX, setPositionX] = useState<'right' | 'left'>('right');
|
const [positionX, setPositionX] = useState<'right' | 'left'>('right');
|
||||||
const [positionY, setPositionY] = useState<'top' | 'bottom'>('bottom');
|
const [positionY, setPositionY] = useState<'top' | 'bottom'>('bottom');
|
||||||
@ -19,7 +20,7 @@ export default (
|
|||||||
const [style, setStyle] = useState('');
|
const [style, setStyle] = useState('');
|
||||||
const [menuStyle, setMenuStyle] = useState('');
|
const [menuStyle, setMenuStyle] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const triggerEl = getTriggerElement();
|
const triggerEl = getTriggerElement();
|
||||||
if (!anchor || !triggerEl) {
|
if (!anchor || !triggerEl) {
|
||||||
return;
|
return;
|
||||||
@ -35,7 +36,7 @@ export default (
|
|||||||
|
|
||||||
const triggerRect = triggerEl.getBoundingClientRect();
|
const triggerRect = triggerEl.getBoundingClientRect();
|
||||||
|
|
||||||
const marginTop = menuEl ? parseInt(getComputedStyle(menuEl).marginTop, 10) : undefined;
|
const marginTop = menuEl ? parseInt(getComputedStyle(menuEl).marginTop, 10) + extraMarginTop : undefined;
|
||||||
|
|
||||||
const menuRect = menuEl ? {
|
const menuRect = menuEl ? {
|
||||||
width: menuEl.offsetWidth,
|
width: menuEl.offsetWidth,
|
||||||
@ -93,7 +94,7 @@ export default (
|
|||||||
setMenuStyle(`max-height: ${menuMaxHeight}px;`);
|
setMenuStyle(`max-height: ${menuMaxHeight}px;`);
|
||||||
setStyle(`left: ${left}px; top: ${top}px`);
|
setStyle(`left: ${left}px; top: ${top}px`);
|
||||||
}, [
|
}, [
|
||||||
anchor, extraPaddingX, extraTopPadding,
|
anchor, extraPaddingX, extraTopPadding, extraMarginTop,
|
||||||
getMenuElement, getRootElement, getTriggerElement, marginSides,
|
getMenuElement, getRootElement, getTriggerElement, marginSides,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user