Audio Player: Prevent rotate-to-refresh when listening voice

This commit is contained in:
Alexander Zinchuk 2021-11-27 17:40:48 +01:00
parent 528137daff
commit f09de4ca28

View File

@ -1,4 +1,6 @@
import React, { FC, useCallback, useMemo } from '../../lib/teact/teact';
import React, {
FC, useCallback, useEffect, useMemo,
} from '../../lib/teact/teact';
import { withGlobal } from '../../lib/teact/teactn';
import { AudioOrigin } from '../../types';
@ -15,13 +17,14 @@ import {
} from '../../modules/helpers';
import { selectChat, selectSender } from '../../modules/selectors';
import { pick } from '../../util/iteratees';
import renderText from '../common/helpers/renderText';
import useAudioPlayer from '../../hooks/useAudioPlayer';
import buildClassName from '../../util/buildClassName';
import useLang from '../../hooks/useLang';
import useMessageMediaMetadata from '../../hooks/useMessageMediaMetadata';
import { makeTrackId } from '../../util/audioPlayer';
import { clearMediaSession } from '../../util/mediaSession';
import windowSize from '../../util/windowSize';
import useAudioPlayer from '../../hooks/useAudioPlayer';
import useLang from '../../hooks/useLang';
import useMessageMediaMetadata from '../../hooks/useMessageMediaMetadata';
import renderText from '../common/helpers/renderText';
import RippleEffect from '../ui/RippleEffect';
import Button from '../ui/Button';
@ -104,6 +107,20 @@ const AudioPlayer: FC<OwnProps & StateProps & DispatchProps> = ({
true,
);
// Prevent refresh by accidentally rotating device when listening to a voice message
const isVoicePlaying = isVoice && isPlaying;
useEffect(() => {
if (!isVoicePlaying) {
return undefined;
}
windowSize.disableRefresh();
return () => {
windowSize.enableRefresh();
};
}, [isVoicePlaying]);
const handleClick = useCallback(() => {
focusMessage({ chatId: message.chatId, messageId: message.id });
}, [focusMessage, message.chatId, message.id]);