RLottie: Fix segment animation (#2985)

This commit is contained in:
Alexander Zinchuk 2023-04-15 13:51:53 +02:00
parent 0070dfa941
commit aaca95737c
2 changed files with 7 additions and 3 deletions

View File

@ -190,7 +190,7 @@ const AnimatedSticker: FC<OwnProps> = ({
} }
if (playSegmentRef.current) { if (playSegmentRef.current) {
animation.playSegment(playSegmentRef.current); animation.playSegment(playSegmentRef.current, viewId);
} else { } else {
animation.play(shouldRestart, viewId); animation.play(shouldRestart, viewId);
} }

View File

@ -116,7 +116,7 @@ class RLottie {
private tgsUrl: string, private tgsUrl: string,
private container: HTMLDivElement | HTMLCanvasElement, private container: HTMLDivElement | HTMLCanvasElement,
private renderId: string, private renderId: string,
private viewId: string = generateIdFor(ID_STORE, true), viewId: string = generateIdFor(ID_STORE, true),
private params: Params = {}, private params: Params = {},
private customColor?: [number, number, number], private customColor?: [number, number, number],
private onLoad?: NoneToVoidFunction | undefined, private onLoad?: NoneToVoidFunction | undefined,
@ -197,10 +197,14 @@ class RLottie {
} }
} }
playSegment([startFrameIndex, stopFrameIndex]: [number, number]) { playSegment([startFrameIndex, stopFrameIndex]: [number, number], viewId?: string) {
if (viewId) {
this.views.get(viewId)!.isPaused = false;
}
this.approxFrameIndex = Math.floor(startFrameIndex / this.reduceFactor); this.approxFrameIndex = Math.floor(startFrameIndex / this.reduceFactor);
this.stopFrameIndex = Math.floor(stopFrameIndex / this.reduceFactor); this.stopFrameIndex = Math.floor(stopFrameIndex / this.reduceFactor);
this.direction = startFrameIndex < stopFrameIndex ? 1 : -1; this.direction = startFrameIndex < stopFrameIndex ? 1 : -1;
this.doPlay(); this.doPlay();
} }