RLottie: Follow-up fixes for sync playing
This commit is contained in:
parent
730e412eeb
commit
9fbd0b7841
@ -42,7 +42,6 @@ let RLottie: RLottieClass;
|
|||||||
|
|
||||||
// Time for the main interface to completely load
|
// Time for the main interface to completely load
|
||||||
const LOTTIE_LOAD_DELAY = 3000;
|
const LOTTIE_LOAD_DELAY = 3000;
|
||||||
|
|
||||||
const ID_STORE = {};
|
const ID_STORE = {};
|
||||||
|
|
||||||
async function ensureLottie() {
|
async function ensureLottie() {
|
||||||
|
|||||||
@ -28,6 +28,7 @@ type OwnProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
loopLimit?: number;
|
loopLimit?: number;
|
||||||
style?: string;
|
style?: string;
|
||||||
|
withSharedAnimation?: boolean;
|
||||||
withGridFix?: boolean;
|
withGridFix?: boolean;
|
||||||
shouldPreloadPreview?: boolean;
|
shouldPreloadPreview?: boolean;
|
||||||
forceOnHeavyAnimation?: boolean;
|
forceOnHeavyAnimation?: boolean;
|
||||||
@ -48,6 +49,7 @@ const CustomEmoji: FC<OwnProps> = ({
|
|||||||
withGridFix,
|
withGridFix,
|
||||||
shouldPreloadPreview,
|
shouldPreloadPreview,
|
||||||
forceOnHeavyAnimation,
|
forceOnHeavyAnimation,
|
||||||
|
withSharedAnimation,
|
||||||
observeIntersection,
|
observeIntersection,
|
||||||
observeIntersectionForPlaying,
|
observeIntersectionForPlaying,
|
||||||
onClick,
|
onClick,
|
||||||
@ -138,6 +140,7 @@ const CustomEmoji: FC<OwnProps> = ({
|
|||||||
observeIntersection={observeIntersection}
|
observeIntersection={observeIntersection}
|
||||||
forceOnHeavyAnimation={forceOnHeavyAnimation}
|
forceOnHeavyAnimation={forceOnHeavyAnimation}
|
||||||
observeIntersectionForPlaying={observeIntersectionForPlaying}
|
observeIntersectionForPlaying={observeIntersectionForPlaying}
|
||||||
|
withSharedAnimation={withSharedAnimation}
|
||||||
onVideoEnded={handleVideoEnded}
|
onVideoEnded={handleVideoEnded}
|
||||||
onAnimatedStickerLoop={handleStickerLoop}
|
onAnimatedStickerLoop={handleStickerLoop}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -230,6 +230,7 @@ const StickerButton = <T extends number | ApiSticker | ApiBotInlineMediaResult |
|
|||||||
shouldPreloadPreview
|
shouldPreloadPreview
|
||||||
noLoad={!shouldLoad}
|
noLoad={!shouldLoad}
|
||||||
noPlay={!shouldPlay}
|
noPlay={!shouldPlay}
|
||||||
|
withSharedAnimation
|
||||||
/>
|
/>
|
||||||
{isLocked && (
|
{isLocked && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import type { ApiSticker } from '../../api/types';
|
|||||||
import { IS_WEBM_SUPPORTED } from '../../util/environment';
|
import { IS_WEBM_SUPPORTED } from '../../util/environment';
|
||||||
import * as mediaLoader from '../../util/mediaLoader';
|
import * as mediaLoader from '../../util/mediaLoader';
|
||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
|
import generateIdFor from '../../util/generateIdFor';
|
||||||
import { getStickerPreviewHash } from '../../global/helpers';
|
import { getStickerPreviewHash } from '../../global/helpers';
|
||||||
import { selectIsAlwaysHighPriorityEmoji } from '../../global/selectors';
|
import { selectIsAlwaysHighPriorityEmoji } from '../../global/selectors';
|
||||||
|
|
||||||
@ -39,12 +40,15 @@ type OwnProps = {
|
|||||||
observeIntersectionForPlaying?: ObserveFn;
|
observeIntersectionForPlaying?: ObserveFn;
|
||||||
noLoad?: boolean;
|
noLoad?: boolean;
|
||||||
noPlay?: boolean;
|
noPlay?: boolean;
|
||||||
|
withSharedAnimation?: boolean;
|
||||||
cacheBuster?: number;
|
cacheBuster?: number;
|
||||||
onVideoEnded?: AnyToVoidFunction;
|
onVideoEnded?: AnyToVoidFunction;
|
||||||
onAnimatedStickerLoop?: AnyToVoidFunction;
|
onAnimatedStickerLoop?: AnyToVoidFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SHARED_PREFIX = 'shared';
|
||||||
const STICKER_SIZE = 24;
|
const STICKER_SIZE = 24;
|
||||||
|
const ID_STORE = {};
|
||||||
|
|
||||||
const StickerView: FC<OwnProps> = ({
|
const StickerView: FC<OwnProps> = ({
|
||||||
containerRef,
|
containerRef,
|
||||||
@ -63,6 +67,7 @@ const StickerView: FC<OwnProps> = ({
|
|||||||
observeIntersectionForPlaying,
|
observeIntersectionForPlaying,
|
||||||
noLoad,
|
noLoad,
|
||||||
noPlay,
|
noPlay,
|
||||||
|
withSharedAnimation,
|
||||||
cacheBuster,
|
cacheBuster,
|
||||||
onVideoEnded,
|
onVideoEnded,
|
||||||
onAnimatedStickerLoop,
|
onAnimatedStickerLoop,
|
||||||
@ -101,7 +106,10 @@ const StickerView: FC<OwnProps> = ({
|
|||||||
// Preload preview for Message Input and local message
|
// Preload preview for Message Input and local message
|
||||||
useMedia(previewMediaHash, !shouldLoad || !shouldPreloadPreview, undefined, cacheBuster);
|
useMedia(previewMediaHash, !shouldLoad || !shouldPreloadPreview, undefined, cacheBuster);
|
||||||
|
|
||||||
const idKey = [id, size, customColor?.join(',')].filter(Boolean).join('_');
|
const [randomIdPrefix] = useState(generateIdFor(ID_STORE, true));
|
||||||
|
const idKey = [
|
||||||
|
(withSharedAnimation ? SHARED_PREFIX : randomIdPrefix), id, size, customColor?.join(','),
|
||||||
|
].filter(Boolean).join('_');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -124,6 +132,7 @@ const StickerView: FC<OwnProps> = ({
|
|||||||
isLowPriority={!selectIsAlwaysHighPriorityEmoji(getGlobal(), stickerSetInfo)}
|
isLowPriority={!selectIsAlwaysHighPriorityEmoji(getGlobal(), stickerSetInfo)}
|
||||||
onLoad={markPlayerReady}
|
onLoad={markPlayerReady}
|
||||||
onLoop={onAnimatedStickerLoop}
|
onLoop={onAnimatedStickerLoop}
|
||||||
|
onEnded={onAnimatedStickerLoop}
|
||||||
/>
|
/>
|
||||||
) : isVideo ? (
|
) : isVideo ? (
|
||||||
<OptimizedVideo
|
<OptimizedVideo
|
||||||
|
|||||||
@ -323,9 +323,10 @@ function processEntity(
|
|||||||
return (
|
return (
|
||||||
<CustomEmoji
|
<CustomEmoji
|
||||||
documentId={entity.documentId}
|
documentId={entity.documentId}
|
||||||
observeIntersection={observeIntersection}
|
|
||||||
withGridFix={!emojiSize}
|
|
||||||
size={emojiSize}
|
size={emojiSize}
|
||||||
|
withSharedAnimation
|
||||||
|
withGridFix={!emojiSize}
|
||||||
|
observeIntersection={observeIntersection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -436,9 +437,10 @@ function processEntity(
|
|||||||
return (
|
return (
|
||||||
<CustomEmoji
|
<CustomEmoji
|
||||||
documentId={entity.documentId}
|
documentId={entity.documentId}
|
||||||
observeIntersection={observeIntersection}
|
|
||||||
withGridFix={!emojiSize}
|
|
||||||
size={emojiSize}
|
size={emojiSize}
|
||||||
|
withSharedAnimation
|
||||||
|
withGridFix={!emojiSize}
|
||||||
|
observeIntersection={observeIntersection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -38,7 +38,7 @@ const CustomEmojiButton: FC<OwnProps> = ({
|
|||||||
onMouseDown={handleClick}
|
onMouseDown={handleClick}
|
||||||
title={emoji.emoji}
|
title={emoji.emoji}
|
||||||
>
|
>
|
||||||
<CustomEmoji documentId={emoji.id} size={CUSTOM_EMOJI_SIZE} shouldPreloadPreview />
|
<CustomEmoji documentId={emoji.id} size={CUSTOM_EMOJI_SIZE} withSharedAnimation shouldPreloadPreview />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -62,12 +62,13 @@ const AnimatedCustomEmoji: FC<OwnProps & StateProps> = ({
|
|||||||
<CustomEmoji
|
<CustomEmoji
|
||||||
ref={ref}
|
ref={ref}
|
||||||
documentId={customEmojiId}
|
documentId={customEmojiId}
|
||||||
|
className={buildClassName('AnimatedEmoji media-inner', sticker?.id === LIKE_STICKER_ID && 'like-sticker-thumb')}
|
||||||
|
style={style}
|
||||||
size={size}
|
size={size}
|
||||||
|
withSharedAnimation
|
||||||
forceOnHeavyAnimation
|
forceOnHeavyAnimation
|
||||||
observeIntersection={observeIntersection}
|
observeIntersection={observeIntersection}
|
||||||
className={buildClassName('AnimatedEmoji media-inner', sticker?.id === LIKE_STICKER_ID && 'like-sticker-thumb')}
|
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
style={style}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -125,6 +125,7 @@ const Sticker: FC<OwnProps> = ({
|
|||||||
shouldLoop={shouldLoop}
|
shouldLoop={shouldLoop}
|
||||||
noLoad={!canLoad}
|
noLoad={!canLoad}
|
||||||
noPlay={!canPlay}
|
noPlay={!canPlay}
|
||||||
|
withSharedAnimation
|
||||||
cacheBuster={lastSyncTime}
|
cacheBuster={lastSyncTime}
|
||||||
/>
|
/>
|
||||||
{hasEffect && canLoad && isPlayingEffect && (
|
{hasEffect && canLoad && isPlayingEffect && (
|
||||||
|
|||||||
@ -132,11 +132,6 @@ class RLottie {
|
|||||||
play(forceRestart = false, container?: HTMLDivElement) {
|
play(forceRestart = false, container?: HTMLDivElement) {
|
||||||
if (container) {
|
if (container) {
|
||||||
this.containers.get(container)!.isPaused = false;
|
this.containers.get(container)!.isPaused = false;
|
||||||
|
|
||||||
const areAllContainersPlaying = Array.from(this.containers.values()).every(({ isPaused }) => !isPaused);
|
|
||||||
if (!areAllContainersPlaying) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isEnded && forceRestart) {
|
if (this.isEnded && forceRestart) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user