Skip to content

Commit

Permalink
fix(loop): updated to use a single Sequence to fix video gaps when lo…
Browse files Browse the repository at this point in the history
…oping
  • Loading branch information
deevus committed May 16, 2023
1 parent ee3ff31 commit 9d0dcc6
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/core/src/loop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {LayoutAndStyle} from '../Sequence.js';
import {Sequence} from '../Sequence.js';
import {useVideoConfig} from '../use-video-config.js';
import {validateDurationInFrames} from '../validation/validate-duration-in-frames.js';
import { useCurrentFrame } from '../use-current-frame.js';

export type LoopProps = {
// The duration of the content to be looped
Expand All @@ -24,7 +25,9 @@ export const Loop: React.FC<LoopProps> = ({
name,
...props
}) => {
const currentFrame = useCurrentFrame();
const {durationInFrames: compDuration} = useVideoConfig();

validateDurationInFrames({
durationInFrames,
component: 'of the <Loop /> component',
Expand Down Expand Up @@ -52,26 +55,20 @@ export const Loop: React.FC<LoopProps> = ({
const maxTimes = Math.ceil(compDuration / durationInFrames);
const actualTimes = Math.min(maxTimes, times);
const style = props.layout === 'none' ? undefined : props.style;
const maxFrame = durationInFrames * (actualTimes - 1);
const start = Math.floor(currentFrame / durationInFrames) * durationInFrames;

return (
<>
{new Array(actualTimes).fill(true).map((_, i) => {
return (
<Sequence
// eslint-disable-next-line react/no-array-index-key
key={`loop-${i}`}
durationInFrames={durationInFrames}
from={i * durationInFrames}
name={name}
showLoopTimesInTimeline={actualTimes}
showInTimeline={i === 0}
layout={props.layout}
style={style}
>
{children}
</Sequence>
);
})}
</>
);
<Sequence
durationInFrames={durationInFrames}
from={Math.min(start, maxFrame)}
name={name}
showLoopTimesInTimeline={actualTimes}
showInTimeline={start === 0}
layout={props.layout}
style={style}
>
{children}
</Sequence>
)
};

0 comments on commit 9d0dcc6

Please # to comment.