From 7954bd9c28c3b1a2bd971c56100ff923dc84e191 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 12 Jun 2024 18:10:39 +0200 Subject: [PATCH] Composer Embedded Message: Suppress animation on chat open (#4594) --- src/api/types/messages.ts | 1 - src/components/common/Composer.tsx | 3 ++ .../composer/ComposerEmbeddedMessage.tsx | 52 ++++++++++--------- .../middle/message/ContextMenuContainer.tsx | 1 + .../middle/message/hooks/useOuterHandlers.ts | 2 +- src/global/actions/api/messages.ts | 1 - src/global/actions/ui/chats.ts | 1 + src/global/actions/ui/messages.ts | 11 +++- src/global/types.ts | 5 ++ 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/api/types/messages.ts b/src/api/types/messages.ts index a3d9237ff..dfb823f2f 100644 --- a/src/api/types/messages.ts +++ b/src/api/types/messages.ts @@ -409,7 +409,6 @@ export interface ApiInputMessageReplyInfo { replyToTopId?: number; replyToPeerId?: string; quoteText?: ApiFormattedText; - isShowingDelayNeeded?: boolean; } export interface ApiInputStoryReplyInfo { diff --git a/src/components/common/Composer.tsx b/src/components/common/Composer.tsx index 9a5386e49..f2d7b6b65 100644 --- a/src/components/common/Composer.tsx +++ b/src/components/common/Composer.tsx @@ -1649,6 +1649,9 @@ const Composer: FC = ({ void; shouldForceShowEditing?: boolean; + chatId: string; + threadId: ThreadId; + messageListType: MessageListType; }; -const FORWARD_RENDERING_DELAY = 300; +const CLOSE_DURATION = 350; const ComposerEmbeddedMessage: FC = ({ replyInfo, @@ -87,7 +90,7 @@ const ComposerEmbeddedMessage: FC = ({ isReplyToDiscussion, onClear, isInChangingRecipientMode, - isChangingChats, + shouldPreventComposerAnimation, senderChat, }) => { const { @@ -99,6 +102,7 @@ const ComposerEmbeddedMessage: FC = ({ setForwardNoAuthors, setForwardNoCaptions, exitForwardMode, + setShouldPreventComposerAnimation, } = getActions(); // eslint-disable-next-line no-null/no-null const ref = useRef(null); @@ -109,27 +113,28 @@ const ComposerEmbeddedMessage: FC = ({ const isReplyWithQuote = Boolean(replyInfo?.quoteText); const isForwarding = Boolean(forwardedMessagesCount); - const isShown = Boolean( - ((replyInfo || editingId) && message && !isInChangingRecipientMode) - || (sender && forwardedMessagesCount), - ); - const canAnimate = useAsyncRendering( - [isShown, isForwarding], - isShown && isChangingChats ? FORWARD_RENDERING_DELAY : undefined, - ); + + const isShown = (() => { + if (isInChangingRecipientMode) return false; + if (sender && isForwarding) return true; + if (message && (replyInfo || editingId)) return true; + return false; + })(); const { shouldRender, transitionClassNames, } = useShowTransition( - canAnimate && isShown && !isReplyToTopicStart && !isReplyToDiscussion, + isShown && !isReplyToTopicStart && !isReplyToDiscussion, undefined, !shouldAnimate, undefined, !shouldAnimate, + CLOSE_DURATION, + !shouldAnimate, ); useEffect(() => { - if (canAnimate && replyInfo?.isShowingDelayNeeded) { - updateDraftReplyInfo({ isShowingDelayNeeded: false }); + if (shouldPreventComposerAnimation) { + setShouldPreventComposerAnimation({ shouldPreventComposerAnimation: false }); } }); @@ -370,22 +375,20 @@ const ComposerEmbeddedMessage: FC = ({ }; export default memo(withGlobal( - (global, { shouldForceShowEditing }): StateProps => { - const { chatId, threadId, type: messageListType } = selectCurrentMessageList(global) || {}; - if (!chatId || !threadId || !messageListType) { - return {}; - } - + (global, { + shouldForceShowEditing, chatId, threadId, messageListType, + }): StateProps => { const { forwardMessages: { fromChatId, toChatId, messageIds: forwardMessageIds, noAuthors, noCaptions, isModalShown, }, + shouldPreventComposerAnimation, } = selectTabState(global); const editingId = messageListType === 'scheduled' ? selectEditingScheduledId(global, chatId) : selectEditingId(global, chatId, threadId); - const shouldAnimate = selectCanAnimateInterface(global); + const shouldAnimate = selectCanAnimateInterface(global) && !shouldPreventComposerAnimation; const isForwarding = toChatId === chatId; const forwardedMessages = forwardMessageIds?.map((id) => selectChatMessage(global, fromChatId!, id)!); @@ -394,7 +397,6 @@ export default memo(withGlobal( const replyToPeerId = replyInfo?.replyToPeerId; const senderChat = replyToPeerId ? selectChat(global, replyToPeerId) : undefined; - const isChangingChats = isForwarding || replyInfo?.isShowingDelayNeeded; let message: ApiMessage | undefined; if (replyInfo && !shouldForceShowEditing) { message = selectChatMessage(global, replyInfo.replyToPeerId || chatId, replyInfo.replyToMsgId); @@ -452,7 +454,7 @@ export default memo(withGlobal( isContextMenuDisabled, isReplyToDiscussion, isInChangingRecipientMode: isModalShown, - isChangingChats, + shouldPreventComposerAnimation, senderChat, }; }, diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index dd8b86bfd..713739603 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -361,6 +361,7 @@ const ContextMenuContainer: FC = ({ updateDraftReplyInfo({ replyToMsgId: message.id, quoteText: canQuoteSelection && selectionRange ? getSelectionAsFormattedText(selectionRange) : undefined, + replyToPeerId: undefined, }); closeMenu(); }); diff --git a/src/components/middle/message/hooks/useOuterHandlers.ts b/src/components/middle/message/hooks/useOuterHandlers.ts index c63bde21d..3e8ff6378 100644 --- a/src/components/middle/message/hooks/useOuterHandlers.ts +++ b/src/components/middle/message/hooks/useOuterHandlers.ts @@ -138,7 +138,7 @@ export default function useOuterHandlers( function handleContainerDoubleClick() { if (IS_TOUCH_ENV || !canReply) return; - updateDraftReplyInfo({ replyToMsgId: messageId }); + updateDraftReplyInfo({ replyToMsgId: messageId, replyToPeerId: undefined, quoteText: undefined }); } function stopPropagation(e: React.MouseEvent) { diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index 019344e04..1d0464634 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -1831,7 +1831,6 @@ addActionHandler('openChatOrTopicWithReplyInDraft', (global, actions, payload): ...currentReplyInfo, replyToPeerId, type: 'message', - isShowingDelayNeeded: true, }; moveReplyToNewDraft(global, threadId, newReply, toChatId); diff --git a/src/global/actions/ui/chats.ts b/src/global/actions/ui/chats.ts index dd8074e40..c5f931302 100644 --- a/src/global/actions/ui/chats.ts +++ b/src/global/actions/ui/chats.ts @@ -47,6 +47,7 @@ addActionHandler('processOpenChatOrThread', (global, actions, payload): ActionRe global = updateTabState(global, { activeReactions: {}, + shouldPreventComposerAnimation: true, }, tabId); } diff --git a/src/global/actions/ui/messages.ts b/src/global/actions/ui/messages.ts index 1c3119e7f..7edb18864 100644 --- a/src/global/actions/ui/messages.ts +++ b/src/global/actions/ui/messages.ts @@ -162,7 +162,9 @@ addActionHandler('replyToNextMessage', (global, actions, payload): ActionReturnT ? Number(chatMessageKeys[newIndex]) : undefined; } - actions.updateDraftReplyInfo({ replyToMsgId: messageId, tabId }); + actions.updateDraftReplyInfo({ + replyToMsgId: messageId, replyToPeerId: undefined, quoteText: undefined, tabId, + }); actions.focusMessage({ chatId, threadId, @@ -496,6 +498,13 @@ addActionHandler('focusMessage', (global, actions, payload): ActionReturnType => return undefined; }); +addActionHandler('setShouldPreventComposerAnimation', (global, actions, payload): ActionReturnType => { + const { shouldPreventComposerAnimation, tabId = getCurrentTabId() } = payload; + return updateTabState(global, { + shouldPreventComposerAnimation, + }, tabId); +}); + addActionHandler('openForwardMenu', (global, actions, payload): ActionReturnType => { const { fromChatId, messageIds, storyId, groupedId, withMyScore, tabId = getCurrentTabId(), diff --git a/src/global/types.ts b/src/global/types.ts index d6b438fb7..c83537e49 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -229,6 +229,7 @@ export type TabState = { isBlurred?: boolean; isMasterTab: boolean; isInactive?: boolean; + shouldPreventComposerAnimation?: boolean; inviteHash?: string; canInstall?: boolean; isChatInfoShown: boolean; @@ -2527,6 +2528,10 @@ export interface ActionPayloads { photo: ApiPhoto; isFallback?: boolean; }; + // Composer + setShouldPreventComposerAnimation: { + shouldPreventComposerAnimation: boolean; + } & WithTabId; // Forwards openForwardMenu: {