Skip to content

πŸŽ₯ Make videos programmatically with React

quality pass over docs and code

Jonny Burger67403bfe7d14
diff --git a/packages/docs/docs/lottie/getlottiemetadata.md b/packages/docs/docs/lottie/getlottiemetadata.md
index f88e5dc17c..48cdfbaa1c 100644
--- a/packages/docs/docs/lottie/getlottiemetadata.md
+++ b/packages/docs/docs/lottie/getlottiemetadata.md
@@ -5,7 +5,7 @@ title: getLottieMetadata()
_Part of the [`@remotion/lottie`](/docs/lottie) package._
-Using this function, you can get basic metadata such as dimensions, duration and framerate of a Lottie animation.
+Using this function, you can get the basic metadata such as dimensions, duration and framerate of a Lottie animation.
```tsx twoslash title="Animation.tsx"
// @allowUmdGlobalAccess
diff --git a/packages/docs/docs/lottie/lottie-aftereffects.md b/packages/docs/docs/lottie/lottie-aftereffects.md
index eef582779d..3d16880a67 100644
--- a/packages/docs/docs/lottie/lottie-aftereffects.md
+++ b/packages/docs/docs/lottie/lottie-aftereffects.md
@@ -51,7 +51,7 @@ Click Render <InlineStep>3</InlineStep> to write the file.
### Import the file into Remotion
-Copy the file into the Remotion project. The recommended way is to the the JSON inside the `public/` folder of Remotion (create it if necessary) and then load it using [`staticFile()`](/docs/staticfile):
+Copy the file into the Remotion project. The recommended way is to put the JSON inside the `public/` folder of Remotion (create it if necessary) and then load it using [`staticFile()`](/docs/staticfile):
```tsx twoslash title="Animation.tsx"
import { continueRender, delayRender, staticFile } from "remotion";
@@ -86,10 +86,11 @@ const Balloons = () => {
## Finetuning
-It is advised to make your composition the same size and duration as the original composition in After Effects. Congrats, you're playing an After Effects animation in Remotion! πŸŽ‰
+It is advised to make your composition [the same size and duration](/docs/lottie/getlottiemetadata) as the original composition in After Effects. Congrats, you're playing an After Effects animation in Remotion! πŸŽ‰
<img src="/img/lottie/result.gif"/>
## See also
-- [Using LottieFiles](/docs/lottie/lottiefiels)
+- [Using LottieFiles](/docs/lottie/lottiefiles)
+- [`getLottieMetadata()`](/docs/lottie/getlottiemetadata)
diff --git a/packages/docs/docs/lottie/lottie-lottiefiles.md b/packages/docs/docs/lottie/lottie-lottiefiles.md
index 466f6c6a50..feb035e938 100644
--- a/packages/docs/docs/lottie/lottie-lottiefiles.md
+++ b/packages/docs/docs/lottie/lottie-lottiefiles.md
@@ -19,7 +19,7 @@ If you find a file that you like, click on it, then click `Download` <InlineStep
### Import the file into Remotion
-Copy the file into the Remotion project. The recommended way is to the the JSON inside the `public/` folder of Remotion (create it if necessary) and then load it using [`staticFile()`](/docs/staticfile):
+Copy the file into the Remotion project. The recommended way is to put the JSON inside the `public/` folder of Remotion (create it if necessary) and then load it using [`staticFile()`](/docs/staticfile):
```tsx twoslash title="Animation.tsx"
import { continueRender, delayRender, staticFile } from "remotion";
diff --git a/packages/example/public/lottie.json b/packages/example/public/lottie.json
deleted file mode 100644
index 9e77077161..0000000000
--- a/packages/example/public/lottie.json
+++ /dev/null
@@ -1 +0,0 @@
-{"v":"5.9.6","fr":29.9700012207031,"ip":0,"op":90.0000036657751,"w":1920,"h":1080,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[360]},{"t":58.0000023623884,"s":[0]}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"t":0,"s":[979.401,1368,0],"to":[0,-138,0],"ti":[0,138,0]},{"t":58.0000023623884,"s":[979.401,540,0]}],"ix":2,"l":2},"a":{"a":0,"k":[517.365,112.096,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[425.883,425.883],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":98,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0,0.468933612108,1,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[494.618,123.481],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 2","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":90.0000036657751,"st":0,"ct":1,"bm":0},{"ddd":0,"ind":2,"ty":1,"nm":"White Solid 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[960,540,0],"ix":2,"l":2},"a":{"a":0,"k":[960,540,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"sw":1920,"sh":1080,"sc":"#ffffff","ip":0,"op":90.0000036657751,"st":0,"bm":0}],"markers":[]}
\ No newline at end of file
diff --git a/packages/lottie/package.json b/packages/lottie/package.json
index dc026c8f4c..952de2813f 100644
--- a/packages/lottie/package.json
+++ b/packages/lottie/package.json
@@ -8,8 +8,7 @@
"lint": "eslint src --ext ts,tsx",
"test": "vitest --run",
"build": "tsc -d",
- "watch": "tsc -w",
- "prerelease": "cp ../../README.md ."
+ "watch": "tsc -w"
},
"repository": {
"url": "https://github.com/remotion-dev/remotion"
@@ -33,7 +32,7 @@
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
- "lottie-web": ">=5"
+ "lottie-web": "^5"
},
"devDependencies": {
"@jonny/eslint-config": "3.0.266",
diff --git a/packages/lottie/src/Lottie.tsx b/packages/lottie/src/Lottie.tsx
index ab0a8c0cbc..55b3782cbb 100644
--- a/packages/lottie/src/Lottie.tsx
+++ b/packages/lottie/src/Lottie.tsx
@@ -5,6 +5,7 @@ import {useEffect, useRef, useState} from 'react';
import {continueRender, delayRender, useCurrentFrame} from 'remotion';
import type {LottieAnimationData} from './types';
import {getNextFrame} from './utils';
+import {validateLoop} from './validate-loop';
import {validatePlaybackRate} from './validate-playbackrate';
export interface LottieProps {
@@ -34,7 +35,7 @@ export const Lottie = ({
animationData,
className,
loop,
- playbackRate = 1,
+ playbackRate,
style,
}: LottieProps) => {
if (typeof animationData !== 'object') {
@@ -44,6 +45,7 @@ export const Lottie = ({
}
validatePlaybackRate(playbackRate);
+ validateLoop(loop);
const animationRef = useRef<AnimationItem>();
const lastFrameRef = useRef<number | null>(null);
@@ -87,7 +89,7 @@ export const Lottie = ({
return;
}
- animationRef.current.setSpeed(playbackRate);
+ animationRef.current.setSpeed(playbackRate ?? 1);
}, [playbackRate]);
useEffect(() => {
@@ -96,7 +98,7 @@ export const Lottie = ({
}
const {totalFrames} = animationRef.current;
- const expectedFrame = frame * playbackRate;
+ const expectedFrame = frame * (playbackRate ?? 1);
const nextFrame = getNextFrame(expectedFrame, totalFrames, loop);
animationRef.current.goToAndStop(nextFrame, true);
diff --git a/packages/lottie/src/validate-loop.ts b/packages/lottie/src/validate-loop.ts
new file mode 100644
index 0000000000..07636b7d8e
--- /dev/null
+++ b/packages/lottie/src/validate-loop.ts
@@ -0,0 +1,13 @@
+export const validateLoop = (loop: unknown) => {
+ if (typeof loop === 'undefined') {
+ return;
+ }
+
+ if (typeof loop !== 'boolean') {
+ throw new TypeError(
+ `The "loop" prop must be a boolean or undefined, but is "${JSON.stringify(
+ loop
+ )}"`
+ );
+ }
+};