Sticker View: Disable grouped video custom emoji on mobile

This commit is contained in:
Alexander Zinchuk 2024-09-24 14:48:33 +02:00
parent 8a32308847
commit cb6c1faa86
4 changed files with 17 additions and 7 deletions

View File

@ -27,6 +27,7 @@ type OwnProps = {
size?: number; size?: number;
isBig?: boolean; isBig?: boolean;
noPlay?: boolean; noPlay?: boolean;
noVideoOnMobile?: boolean;
loopLimit?: number; loopLimit?: number;
isSelectable?: boolean; isSelectable?: boolean;
withSharedAnimation?: boolean; withSharedAnimation?: boolean;
@ -52,6 +53,7 @@ const CustomEmoji: FC<OwnProps> = ({
size = STICKER_SIZE, size = STICKER_SIZE,
isBig, isBig,
noPlay, noPlay,
noVideoOnMobile,
loopLimit, loopLimit,
isSelectable, isSelectable,
withSharedAnimation, withSharedAnimation,
@ -142,6 +144,7 @@ const CustomEmoji: FC<OwnProps> = ({
isSmall={!isBig} isSmall={!isBig}
size={size} size={size}
noPlay={noPlay || !(shouldPlay && canPlay)} noPlay={noPlay || !(shouldPlay && canPlay)}
noVideoOnMobile={noVideoOnMobile}
thumbClassName={styles.thumb} thumbClassName={styles.thumb}
fullMediaClassName={styles.media} fullMediaClassName={styles.media}
shouldLoop shouldLoop

View File

@ -299,6 +299,7 @@ const StickerButton = <T extends number | ApiSticker | ApiBotInlineMediaResult |
shouldPreloadPreview shouldPreloadPreview
noLoad={!shouldLoad} noLoad={!shouldLoad}
noPlay={!shouldPlay} noPlay={!shouldPlay}
noVideoOnMobile
withSharedAnimation withSharedAnimation
sharedCanvasRef={sharedCanvasRef} sharedCanvasRef={sharedCanvasRef}
withTranslucentThumb={withTranslucentThumb} withTranslucentThumb={withTranslucentThumb}

View File

@ -1,5 +1,5 @@
import type { FC } from '../../lib/teact/teact'; import type { FC } from '../../lib/teact/teact';
import React, { memo, useRef } from '../../lib/teact/teact'; import React, { memo, useMemo, useRef } from '../../lib/teact/teact';
import { getGlobal } from '../../global'; import { getGlobal } from '../../global';
import type { ApiSticker } from '../../api/types'; import type { ApiSticker } from '../../api/types';
@ -9,7 +9,7 @@ import { getStickerMediaHash } from '../../global/helpers';
import { selectIsAlwaysHighPriorityEmoji } from '../../global/selectors'; import { selectIsAlwaysHighPriorityEmoji } from '../../global/selectors';
import buildClassName from '../../util/buildClassName'; import buildClassName from '../../util/buildClassName';
import * as mediaLoader from '../../util/mediaLoader'; import * as mediaLoader from '../../util/mediaLoader';
import { IS_WEBM_SUPPORTED } from '../../util/windowEnvironment'; import { IS_ANDROID, IS_IOS, IS_WEBM_SUPPORTED } from '../../util/windowEnvironment';
import useColorFilter from '../../hooks/stickers/useColorFilter'; import useColorFilter from '../../hooks/stickers/useColorFilter';
import useCoordsInSharedCanvas from '../../hooks/useCoordsInSharedCanvas'; import useCoordsInSharedCanvas from '../../hooks/useCoordsInSharedCanvas';
@ -45,6 +45,7 @@ type OwnProps = {
observeIntersectionForPlaying?: ObserveFn; observeIntersectionForPlaying?: ObserveFn;
noLoad?: boolean; noLoad?: boolean;
noPlay?: boolean; noPlay?: boolean;
noVideoOnMobile?: boolean;
withSharedAnimation?: boolean; withSharedAnimation?: boolean;
sharedCanvasRef?: React.RefObject<HTMLCanvasElement>; sharedCanvasRef?: React.RefObject<HTMLCanvasElement>;
withTranslucentThumb?: boolean; // With shared canvas thumbs are opaque by default to provide better transition effect withTranslucentThumb?: boolean; // With shared canvas thumbs are opaque by default to provide better transition effect
@ -73,6 +74,7 @@ const StickerView: FC<OwnProps> = ({
observeIntersectionForPlaying, observeIntersectionForPlaying,
noLoad, noLoad,
noPlay, noPlay,
noVideoOnMobile,
withSharedAnimation, withSharedAnimation,
withTranslucentThumb, withTranslucentThumb,
sharedCanvasRef, sharedCanvasRef,
@ -83,8 +85,11 @@ const StickerView: FC<OwnProps> = ({
id, isLottie, stickerSetInfo, emoji, id, isLottie, stickerSetInfo, emoji,
} = sticker; } = sticker;
const [isVideoBroken, markVideoBroken] = useFlag(); const [isVideoBroken, markVideoBroken] = useFlag();
const isUnsupportedVideo = sticker.isVideo && !IS_WEBM_SUPPORTED; const isUnsupportedVideo = sticker.isVideo && (
const isVideo = sticker.isVideo && !isUnsupportedVideo; !IS_WEBM_SUPPORTED
|| (noVideoOnMobile && (IS_IOS || IS_ANDROID))
);
const isVideo = sticker.isVideo;
const isStatic = !isLottie && !isVideo; const isStatic = !isLottie && !isVideo;
const previewMediaHash = getStickerMediaHash(sticker, 'preview'); const previewMediaHash = getStickerMediaHash(sticker, 'preview');
@ -115,7 +120,7 @@ const StickerView: FC<OwnProps> = ({
fullMediaHash === previewMediaHash && (cachedPreview || previewMediaData) fullMediaHash === previewMediaHash && (cachedPreview || previewMediaData)
)); ));
const fullMediaData = useMedia(fullMediaHash || `sticker${id}`, !shouldLoad || shouldSkipFullMedia); const fullMediaData = useMedia(fullMediaHash || `sticker${id}`, !shouldLoad || shouldSkipFullMedia);
const shouldRenderFullMedia = isReadyToMountFullMedia && fullMediaData && !isVideoBroken; const shouldRenderFullMedia = isReadyToMountFullMedia && !shouldSkipFullMedia && fullMediaData && !isVideoBroken;
const [isPlayerReady, markPlayerReady] = useFlag(); const [isPlayerReady, markPlayerReady] = useFlag();
const isFullMediaReady = shouldRenderFullMedia && (isStatic || isPlayerReady); const isFullMediaReady = shouldRenderFullMedia && (isStatic || isPlayerReady);
@ -137,13 +142,13 @@ const StickerView: FC<OwnProps> = ({
useMedia(previewMediaHash, !shouldLoad || !shouldPreloadPreview); useMedia(previewMediaHash, !shouldLoad || !shouldPreloadPreview);
const randomIdPrefix = useUniqueId(); const randomIdPrefix = useUniqueId();
const renderId = [ const renderId = useMemo(() => ([
(withSharedAnimation ? SHARED_PREFIX : randomIdPrefix), (withSharedAnimation ? SHARED_PREFIX : randomIdPrefix),
id, id,
size, size,
(withSharedAnimation ? customColor : undefined), (withSharedAnimation ? customColor : undefined),
dpr, dpr,
].filter(Boolean).join('_'); ].filter(Boolean).join('_')), [customColor, dpr, id, randomIdPrefix, size, withSharedAnimation]);
return ( return (
<> <>

View File

@ -166,6 +166,7 @@ const ReactionAnimatedEmoji = ({
className={styles.customEmoji} className={styles.customEmoji}
size={size} size={size}
noPlay={shouldPause} noPlay={shouldPause}
noVideoOnMobile
loopLimit={loopLimit} loopLimit={loopLimit}
observeIntersectionForPlaying={observeIntersection} observeIntersectionForPlaying={observeIntersection}
/> />