<Loop>
available from v2.5.0
The <Loop />
component allows you to quickly lay out an animation so it repeats itself.
API
The Loop component is a high order component and accepts, besides it's children, the following props:
durationInFrames
(required): How many frames of the content the loop should include.times
(optional): How many times to loop the content. By default it will beInfinity
.layout
: (optional): Either"absolute-fill"
(default) or"none"
By default, your content will be absolutely positioned. If you would like to disable layout side effects, passlayout="none"
.
Good to know: You can nest loops within each other and they will cascade. For example, a loop that has a duration of 30 frames which is inside a loop that has a duration of 75 will play 2 times. However, nested loops are not currently displayed in the timeline.
Examples
All the examples below are based on the following animation of a blue square:
tsx
constMyVideo = () => {return <BlueSquare />;};
tsx
constMyVideo = () => {return <BlueSquare />;};
Continuous loop
tsx
constMyVideo = () => {return (<Loop durationInFrames ={50}><BlueSquare /></Loop >);};
tsx
constMyVideo = () => {return (<Loop durationInFrames ={50}><BlueSquare /></Loop >);};
Fixed count loop
tsx
constMyVideo = () => {return (<Loop durationInFrames ={50}times ={2}><BlueSquare /></Loop >);};
tsx
constMyVideo = () => {return (<Loop durationInFrames ={50}times ={2}><BlueSquare /></Loop >);};
Nested loop
tsx
constMyVideo = () => {return (<Loop durationInFrames ={75}><Loop durationInFrames ={30}><BlueSquare /></Loop ></Loop >);};
tsx
constMyVideo = () => {return (<Loop durationInFrames ={75}><Loop durationInFrames ={30}><BlueSquare /></Loop ></Loop >);};