[Perf] Composer: Better sending animation for old/slow iPhones (#1252)

This commit is contained in:
Alexander Zinchuk 2021-07-08 18:00:58 +03:00
parent de14c30c4a
commit a877d6e497
3 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,7 @@ import {
import { LangCode } from '../../../types'; import { LangCode } from '../../../types';
import { EDITABLE_INPUT_ID, SCHEDULED_WHEN_ONLINE } from '../../../config'; import { EDITABLE_INPUT_ID, SCHEDULED_WHEN_ONLINE } from '../../../config';
import { IS_VOICE_RECORDING_SUPPORTED, IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment'; import { IS_VOICE_RECORDING_SUPPORTED, IS_SINGLE_COLUMN_LAYOUT, IS_IOS } from '../../../util/environment';
import { import {
selectChat, selectChat,
selectIsChatWithBot, selectIsChatWithBot,
@ -50,6 +50,7 @@ import deleteLastCharacterOutsideSelection from '../../../util/deleteLastCharact
import { pick } from '../../../util/iteratees'; import { pick } from '../../../util/iteratees';
import buildClassName from '../../../util/buildClassName'; import buildClassName from '../../../util/buildClassName';
import { isSelectionInsideInput } from './helpers/selection'; import { isSelectionInsideInput } from './helpers/selection';
import applyIosAutoCapitalizationFix from './helpers/applyIosAutoCapitalizationFix';
import useFlag from '../../../hooks/useFlag'; import useFlag from '../../../hooks/useFlag';
import useVoiceRecording from './hooks/useVoiceRecording'; import useVoiceRecording from './hooks/useVoiceRecording';
@ -442,6 +443,8 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
return; return;
} }
const messageInput = document.getElementById(EDITABLE_INPUT_ID)!;
if (currentAttachments.length || text) { if (currentAttachments.length || text) {
if (slowMode && !isAdmin) { if (slowMode && !isAdmin) {
const nowSeconds = Math.floor(Date.now() / 1000) + serverTimeOffset; const nowSeconds = Math.floor(Date.now() / 1000) + serverTimeOffset;
@ -464,7 +467,6 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
}, },
}); });
const messageInput = document.getElementById(EDITABLE_INPUT_ID)!;
messageInput.blur(); messageInput.blur();
return; return;
@ -487,6 +489,10 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
clearDraft({ chatId, localOnly: true }); clearDraft({ chatId, localOnly: true });
if (IS_IOS && messageInput === document.activeElement) {
applyIosAutoCapitalizationFix(messageInput);
}
// Wait until message animation starts // Wait until message animation starts
requestAnimationFrame(resetComposer); requestAnimationFrame(resetComposer);
}, [ }, [

View File

@ -1,6 +1,6 @@
import { ChangeEvent } from 'react'; import { ChangeEvent } from 'react';
import React, { import React, {
FC, useEffect, useRef, memo, useState, useCallback, useLayoutEffect, FC, useEffect, useRef, memo, useState, useCallback,
} from '../../../lib/teact/teact'; } from '../../../lib/teact/teact';
import { withGlobal } from '../../../lib/teact/teactn'; import { withGlobal } from '../../../lib/teact/teactn';
@ -22,7 +22,6 @@ import useFlag from '../../../hooks/useFlag';
import parseEmojiOnlyString from '../../common/helpers/parseEmojiOnlyString'; import parseEmojiOnlyString from '../../common/helpers/parseEmojiOnlyString';
import { isSelectionInsideInput } from './helpers/selection'; import { isSelectionInsideInput } from './helpers/selection';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import applyIosAutoCapitalizationFix from './helpers/applyIosAutoCapitalizationFix';
import TextFormatter from './TextFormatter'; import TextFormatter from './TextFormatter';
@ -105,12 +104,6 @@ const MessageInput: FC<OwnProps & StateProps & DispatchProps> = ({
updateInputHeight(false); updateInputHeight(false);
}, []); }, []);
useLayoutEffect(() => {
if (IS_IOS && !html && inputRef.current === document.activeElement) {
applyIosAutoCapitalizationFix(inputRef.current!);
}
}, [html]);
useLayoutEffectWithPrevDeps(([prevHtml]) => { useLayoutEffectWithPrevDeps(([prevHtml]) => {
if (html !== inputRef.current!.innerHTML) { if (html !== inputRef.current!.innerHTML) {
inputRef.current!.innerHTML = html; inputRef.current!.innerHTML = html;

View File

@ -53,6 +53,7 @@ import {
} from '../../selectors'; } from '../../selectors';
import { rafPromise, throttle } from '../../../util/schedulers'; import { rafPromise, throttle } from '../../../util/schedulers';
import { copyTextToClipboard } from '../../../util/clipboard'; import { copyTextToClipboard } from '../../../util/clipboard';
import { IS_IOS } from '../../../util/environment';
const uploadProgressCallbacks = new Map<number, ApiOnProgress>(); const uploadProgressCallbacks = new Map<number, ApiOnProgress>();
@ -740,7 +741,7 @@ async function sendMessage(params: {
} : undefined; } : undefined;
// @optimization // @optimization
if (params.replyingTo) { if (params.replyingTo || IS_IOS) {
await rafPromise(); await rafPromise();
} }