Skip to content

🎥 Make videos programmatically with React

overhaul animate properties page

Jonny Burger3244e79be18f
diff --git a/packages/docs/components/DocsDark.tsx b/packages/docs/components/DocsDark.tsx
new file mode 100644
index 0000000000..b8f2955bcc
--- /dev/null
+++ b/packages/docs/components/DocsDark.tsx
@@ -0,0 +1,84 @@
+import { useColorMode } from "@docusaurus/theme-common";
+import React, { useEffect, useMemo, useRef } from "react";
+import { useMobileLayout } from "../src/helpers/mobile-layout";
+import { Spacer } from "./layout/Spacer";
+
+export const AnimatingProperties: React.FC = () => {
+ const { colorMode } = useColorMode();
+ const mobile = useMobileLayout();
+
+ const ref1 = useRef<HTMLVideoElement>(null);
+ const ref2 = useRef<HTMLVideoElement>(null);
+
+ const style: React.CSSProperties = useMemo(
+ () => ({
+ display: "flex",
+ flexDirection: mobile ? "column" : "row",
+ }),
+ [mobile]
+ );
+
+ const videoContainer: React.CSSProperties = useMemo(() => {
+ return {
+ border:
+ "1px solid " +
+ (colorMode === "dark"
+ ? "transparent"
+ : "var(--ifm-color-emphasis-300)"),
+ flex: mobile ? 0 : 1,
+ display: "block",
+ overflow: "hidden",
+ borderRadius: "var(--ifm-code-border-radius)",
+ aspectRatio: "16/9",
+ };
+ }, [colorMode, mobile]);
+
+ useEffect(() => {
+ Promise.all([
+ new Promise<void>((resolve) => {
+ ref1.current.addEventListener("loadeddata", () => resolve(), {
+ once: true,
+ });
+ }),
+ new Promise<void>((resolve) => {
+ ref2.current.addEventListener("loadeddata", () => resolve(), {
+ once: true,
+ });
+ }),
+ ]).then(() => {
+ ref1.current.play();
+ ref2.current.play();
+ });
+ }, [colorMode]);
+
+ return (
+ <div style={style}>
+ <div style={videoContainer}>
+ <video
+ ref={ref1}
+ src={
+ colorMode === "dark"
+ ? "/img/animating-properties-left-dark.mp4"
+ : "/img/animating-properties-left-light.mp4"
+ }
+ muted
+ loop
+ />
+ </div>
+ <Spacer />
+ <Spacer />
+ <div style={videoContainer}>
+ <video
+ ref={ref2}
+ src={
+ colorMode === "dark"
+ ? "/img/animating-properties-right-dark.mp4"
+ : "/img/animating-properties-right-light.mp4"
+ }
+ muted
+ loop
+ />
+ </div>
+ </div>
+ );
+};
diff --git a/packages/docs/docs/animating-properties.md b/packages/docs/docs/animating-properties.md
index 3ef382af85..6386d01be4 100644
--- a/packages/docs/docs/animating-properties.md
+++ b/packages/docs/docs/animating-properties.md
@@ -3,37 +3,41 @@ id: animating-properties
title: Animating properties
---
-**Animation is all about how properties change over time.**
-Let's start with a simple example, let's say we want to create a fade in animation.
+import {AnimatingProperties} from '../components/DocsDark'
-If we want to fade the text in over 20 frames, we need to gradually change the `opacity` style over time so that it goes from 0 to 1.
+Animation works by changing properties over time.
+Let's create a simple fade in animation.
-```tsx twoslash {4, 12}
-import { useCurrentFrame } from "remotion";
+If we want to fade the text in over 60 frames, we need to gradually change the `opacity` over time so that it goes from 0 to 1.
+
+```tsx twoslash {4, 15} title="FadeIn.tsx"
+import { AbsoluteFill, useCurrentFrame } from "remotion";
// ---cut---
-export const MyVideo = () => {
+export const FadeIn = () => {
const frame = useCurrentFrame();
- const opacity = frame >= 20 ? 1 : frame / 20;
+ const opacity = Math.min(1, frame / 60);
return (
- <div
+ <AbsoluteFill
style={{
- flex: 1,
- textAlign: "center",
- fontSize: "7em",
- opacity: opacity,
+ justifyContent: "center",
+ alignItems: "center",
+ backgroundColor: "white",
+ fontSize: 80,
}}
>
- Hello World!
- </div>
+ <div style={{ opacity: opacity }}>Hello World!</div>
+ </AbsoluteFill>
);
};
```
+<AnimatingProperties />
+
## Using the interpolate helper function
-Using the [`interpolate`](/docs/interpolate) function can make animations more readable.
+Using the [`interpolate()`](/docs/interpolate) function can make animations more readable.
The function takes 4 arguments:
1. The input value
diff --git a/packages/docs/docs/the-fundamentals.md b/packages/docs/docs/the-fundamentals.md
index 39783e75f8..90bf0aa2be 100644
--- a/packages/docs/docs/the-fundamentals.md
+++ b/packages/docs/docs/the-fundamentals.md
@@ -15,6 +15,7 @@ export const MyComposition = () => {
justifyContent: "center",
alignItems: "center",
fontSize: 100,
+ backgroundColor: "white"
}}
>
The current frame is {frame}.
@@ -56,6 +57,7 @@ export const MyComposition = () => {
justifyContent: "center",
alignItems: "center",
fontSize: 60,
+ backgroundColor: "white",
}}
>
This {width}x{height}px video is {durationInFrames / fps} seconds long.
diff --git a/packages/docs/static/img/animating-properties-dark.mp4 b/packages/docs/static/img/animating-properties-dark.mp4
new file mode 100644
index 0000000000..72ebcf0ea1
Binary files /dev/null and b/packages/docs/static/img/animating-properties-dark.mp4 differ
diff --git a/packages/docs/static/img/animating-properties-left-dark.mp4 b/packages/docs/static/img/animating-properties-left-dark.mp4
new file mode 100644
index 0000000000..c92690aeb0
Binary files /dev/null and b/packages/docs/static/img/animating-properties-left-dark.mp4 differ
diff --git a/packages/docs/static/img/animating-properties-left-light.mp4 b/packages/docs/static/img/animating-properties-left-light.mp4
new file mode 100644
index 0000000000..a1a900583b
Binary files /dev/null and b/packages/docs/static/img/animating-properties-left-light.mp4 differ
diff --git a/packages/docs/static/img/animating-properties-light.mp4 b/packages/docs/static/img/animating-properties-light.mp4
new file mode 100644
index 0000000000..62afa92808
Binary files /dev/null and b/packages/docs/static/img/animating-properties-light.mp4 differ
diff --git a/packages/docs/static/img/animating-properties-right-dark.mp4 b/packages/docs/static/img/animating-properties-right-dark.mp4
new file mode 100644
index 0000000000..48234c1371
Binary files /dev/null and b/packages/docs/static/img/animating-properties-right-dark.mp4 differ
diff --git a/packages/docs/static/img/animating-properties-right-light.mp4 b/packages/docs/static/img/animating-properties-right-light.mp4
new file mode 100644
index 0000000000..4d0ff49f3e
Binary files /dev/null and b/packages/docs/static/img/animating-properties-right-light.mp4 differ