Message List: Fix selection buttons not showing (#6960)

This commit is contained in:
zubiden 2026-06-01 01:15:49 +02:00 committed by Alexander Zinchuk
parent 2b6fca15bc
commit 198da4736e
2 changed files with 46 additions and 15 deletions

View File

@ -1,6 +1,6 @@
import type React from '@teact'; import type React from '@teact';
import type { ElementRef } from '@teact'; import type { ElementRef } from '@teact';
import { memo, useEffect, useMemo, useState } from '@teact'; import { memo, useEffect, useMemo, useRef, useState } from '@teact';
import { getActions, withGlobal } from '../../global'; import { getActions, withGlobal } from '../../global';
import type { ApiChat, ApiChatBannedRights, ApiInputMessageReplyInfo, ApiTopic } from '../../api/types'; import type { ApiChat, ApiChatBannedRights, ApiInputMessageReplyInfo, ApiTopic } from '../../api/types';
@ -61,6 +61,7 @@ import {
import buildClassName from '../../util/buildClassName'; import buildClassName from '../../util/buildClassName';
import buildStyle from '../../util/buildStyle'; import buildStyle from '../../util/buildStyle';
import captureEscKeyListener from '../../util/captureEscKeyListener'; import captureEscKeyListener from '../../util/captureEscKeyListener';
import { waitForTransitionEnd } from '../../util/cssAnimationEndListeners';
import { isUserId } from '../../util/entities/ids'; import { isUserId } from '../../util/entities/ids';
import { resolveTransitionName } from '../../util/resolveTransitionName'; import { resolveTransitionName } from '../../util/resolveTransitionName';
import calculateMiddleFooterTransforms from './helpers/calculateMiddleFooterTransforms'; import calculateMiddleFooterTransforms from './helpers/calculateMiddleFooterTransforms';
@ -292,12 +293,16 @@ function MiddleColumn({
prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined
); );
const { isReady, handleCssTransitionEnd, handleSlideTransitionStop } = useIsReady( const middleColumnRef = useRef<HTMLDivElement>();
const { isReady, handleSlideTransitionStop } = useIsReady(
!shouldSkipHistoryAnimations && withInterfaceAnimations, !shouldSkipHistoryAnimations && withInterfaceAnimations,
currentTransitionKey, currentTransitionKey,
prevTransitionKey, prevTransitionKey,
chatId, chatId,
isMobile, isMobile,
isLeftColumnShown,
middleColumnRef,
); );
useEffect(() => { useEffect(() => {
@ -501,9 +506,9 @@ function MiddleColumn({
return ( return (
<div <div
ref={middleColumnRef}
id="MiddleColumn" id="MiddleColumn"
className={className} className={className}
onTransitionEnd={handleCssTransitionEnd}
style={buildStyle( style={buildStyle(
`--composer-hidden-scale: ${composerHiddenScale}`, `--composer-hidden-scale: ${composerHiddenScale}`,
`--toolbar-hidden-scale: ${toolbarHiddenScale}`, `--toolbar-hidden-scale: ${toolbarHiddenScale}`,
@ -896,6 +901,8 @@ function useIsReady(
prevTransitionKey?: number, prevTransitionKey?: number,
chatId?: string, chatId?: string,
isMobile?: boolean, isMobile?: boolean,
isLeftColumnShown?: boolean,
middleColumnRef?: ElementRef<HTMLDivElement>,
) { ) {
const [isReady, setIsReady] = useState(!isMobile); const [isReady, setIsReady] = useState(!isMobile);
const forceUpdate = useForceUpdate(); const forceUpdate = useForceUpdate();
@ -910,13 +917,9 @@ function useIsReady(
setIsReady(false); setIsReady(false);
// Make sure to end even if end callback was not called (which was some hardly-reproducible bug) // Make sure to end even if end callback was not called (which was some hardly-reproducible bug)
const timeout = setTimeout(() => { window.setTimeout(() => {
setIsReady(true); setIsReady(true);
}, LAYER_ANIMATION_DURATION_MS); }, LAYER_ANIMATION_DURATION_MS);
return () => {
clearTimeout(timeout);
};
}, [willSwitchMessageList, withAnimations]); }, [willSwitchMessageList, withAnimations]);
useSyncEffect(() => { useSyncEffect(() => {
@ -925,11 +928,40 @@ function useIsReady(
} }
}, [withAnimations]); }, [withAnimations]);
function handleCssTransitionEnd(e: React.TransitionEvent<HTMLDivElement>) { // Mobile only: wait until `MiddleColumn` slides in after the left column closes
if (e.propertyName === 'transform' && e.target === e.currentTarget) { useSyncEffect(([prevIsLeftColumnShown, prevWillSwitchMessageList]) => {
setIsReady(Boolean(chatId)); if (!isMobile) {
return;
} }
}
if (!chatId) {
setIsReady(false);
return;
}
if (!withAnimations) {
setIsReady(true);
return;
}
if (willSwitchMessageList || prevWillSwitchMessageList) {
return;
}
if (isLeftColumnShown) {
setIsReady(false);
return;
}
if (prevIsLeftColumnShown !== true) {
setIsReady(true);
return;
}
waitForTransitionEnd(middleColumnRef!.current!, () => {
setIsReady(true);
}, 'transform', LAYER_ANIMATION_DURATION_MS);
}, [isLeftColumnShown, willSwitchMessageList, chatId, isMobile, withAnimations, middleColumnRef]);
function handleSlideTransitionStop() { function handleSlideTransitionStop() {
setIsReady(true); setIsReady(true);
@ -937,7 +969,6 @@ function useIsReady(
return { return {
isReady: isReady && !willSwitchMessageList, isReady: isReady && !willSwitchMessageList,
handleCssTransitionEnd: withAnimations ? handleCssTransitionEnd : undefined,
handleSlideTransitionStop: withAnimations ? handleSlideTransitionStop : undefined, handleSlideTransitionStop: withAnimations ? handleSlideTransitionStop : undefined,
}; };
} }

View File

@ -32,8 +32,8 @@ function waitForEndEvent(
} }
if (detailedName && ( if (detailedName && (
(e instanceof TransitionEvent && e.propertyName === detailedName) (e instanceof TransitionEvent && e.propertyName !== detailedName)
|| (e instanceof AnimationEvent && e.animationName === detailedName) || (e instanceof AnimationEvent && e.animationName !== detailedName)
)) { )) {
return; return;
} }