🎥 Make videos programmatically with React
explain spring animation
Jonny Burgerfe2ffab54436
diff --git a/packages/docs/components/DocsDark.tsx b/packages/docs/components/DocsDark.tsxindex b8f2955bcc..9b6bfff984 100644--- a/packages/docs/components/DocsDark.tsx+++ b/packages/docs/components/DocsDark.tsx@@ -1,15 +1,27 @@import { useColorMode } from "@docusaurus/theme-common";+import { PlayerInternals } from "@remotion/player";import React, { useEffect, useMemo, useRef } from "react";-import { useMobileLayout } from "../src/helpers/mobile-layout";import { Spacer } from "./layout/Spacer";-export const AnimatingProperties: React.FC = () => {+export const DualVideoDemo: React.FC<{+ leftDark: string;+ leftLight: string;+ rightDark: string;+ rightLight: string;+}> = ({ leftDark, leftLight, rightDark, rightLight }) => {const { colorMode } = useColorMode();- const mobile = useMobileLayout();+ const container = useRef<HTMLDivElement>(null);const ref1 = useRef<HTMLVideoElement>(null);const ref2 = useRef<HTMLVideoElement>(null);+ const size = PlayerInternals.useElementSize(container, {+ triggerOnWindowResize: false,+ shouldApplyCssTransforms: true,+ });++ const mobile = size?.width < 700;+const style: React.CSSProperties = useMemo(() => ({display: "flex",@@ -52,15 +64,11 @@ export const AnimatingProperties: React.FC = () => {}, [colorMode]);return (- <div style={style}>+ <div ref={container} style={style}><div style={videoContainer}><videoref={ref1}- src={- colorMode === "dark"- ? "/img/animating-properties-left-dark.mp4"- : "/img/animating-properties-left-light.mp4"- }+ src={colorMode === "dark" ? leftDark : leftLight}mutedloop/>@@ -70,11 +78,7 @@ export const AnimatingProperties: React.FC = () => {<div style={videoContainer}><videoref={ref2}- src={- colorMode === "dark"- ? "/img/animating-properties-right-dark.mp4"- : "/img/animating-properties-right-light.mp4"- }+ src={colorMode === "dark" ? rightDark : rightLight}mutedloop/>@@ -82,3 +86,29 @@ export const AnimatingProperties: React.FC = () => {</div>);};++export const AnimatingProperties: React.FC = () => {+ return (+ <div>+ <DualVideoDemo+ leftDark="/img/animating-properties-left-dark.mp4"+ leftLight="/img/animating-properties-left-light.mp4"+ rightDark="/img/animating-properties-right-dark.mp4"+ rightLight="/img/animating-properties-right-light.mp4"+ />+ </div>+ );+};++export const Springs: React.FC = () => {+ return (+ <div>+ <DualVideoDemo+ leftDark="/img/spring-left-dark.mp4"+ leftLight="/img/spring-left-light.mp4"+ rightDark="/img/spring-right-dark.mp4"+ rightLight="/img/spring-right-light.mp4"+ />+ </div>+ );+};diff --git a/packages/docs/docs/animating-properties.md b/packages/docs/docs/animating-properties.mdindex 74bcfb05f6..1e70666444 100644--- a/packages/docs/docs/animating-properties.md+++ b/packages/docs/docs/animating-properties.md@@ -3,7 +3,7 @@ id: animating-propertiestitle: Animating properties----import {AnimatingProperties} from '../components/DocsDark'+import {AnimatingProperties, Springs} from '../components/DocsDark'Animation works by changing properties over time.Let's create a simple fade in animation.@@ -74,9 +74,9 @@ In this example, we map the frames 0 to 60 to their opacity values `(0, 0.0166,## Using spring animations-Spring animations are a beautiful way to put things into motion and make them natural. Remotion includes a helper function to make spring animations easy! This time, let's animate the scale of the text.+Spring animations are a beautiful animation primitive. This time, let's animate the scale of the text.-```tsx twoslash {7-12, 22}+```tsx twoslash {7-12, 20}import { spring, useCurrentFrame, useVideoConfig } from "remotion";export const MyVideo = () => {@@ -85,8 +85,6 @@ export const MyVideo = () => {const scale = spring({fps,- from: 0,- to: 1,frame,});@@ -104,7 +102,12 @@ export const MyVideo = () => {};```-You should see the text 'jump in'. The default spring configuration leads to a little bit of overshoot, meaning the text will bounce a little bit. See the reference page about the [`spring()`](/docs/spring) function to learn how to customize your spring animations.+You should see the text jump in.++<Springs />+<br />++The default spring configuration leads to a little bit of overshoot, meaning the text will bounce a little bit. See the documentation page for [`spring()`](/docs/spring) to learn how to customize it.## Always animate using `useCurrentFrame()`diff --git a/packages/docs/static/img/spring-left-dark.mp4 b/packages/docs/static/img/spring-left-dark.mp4new file mode 100644index 0000000000..44d88d5c19Binary files /dev/null and b/packages/docs/static/img/spring-left-dark.mp4 differdiff --git a/packages/docs/static/img/spring-left-light.mp4 b/packages/docs/static/img/spring-left-light.mp4new file mode 100644index 0000000000..d73d767b28Binary files /dev/null and b/packages/docs/static/img/spring-left-light.mp4 differdiff --git a/packages/docs/static/img/spring-right-dark.mp4 b/packages/docs/static/img/spring-right-dark.mp4new file mode 100644index 0000000000..462434df46Binary files /dev/null and b/packages/docs/static/img/spring-right-dark.mp4 differdiff --git a/packages/docs/static/img/spring-right-light.mp4 b/packages/docs/static/img/spring-right-light.mp4new file mode 100644index 0000000000..b10fcc22e4Binary files /dev/null and b/packages/docs/static/img/spring-right-light.mp4 differ