Skip to content

🎥 Make videos programmatically with React

document spring timing

Jonny Burger8646247dc621
diff --git a/packages/docs/components/TableOfContents/transitions.tsx b/packages/docs/components/TableOfContents/transitions.tsx
index bf6d47e8bd..7587778ece 100644
--- a/packages/docs/components/TableOfContents/transitions.tsx
+++ b/packages/docs/components/TableOfContents/transitions.tsx
@@ -64,7 +64,10 @@ export const TableOfContents: React.FC = () => {
</TOCItem>
<TOCItem link="/docs/transitions/presentations/fade">
<div style={row}>
- <PresentationPreview effect={fade()} />
+ <PresentationPreview
+ durationRestThreshold={0.001}
+ effect={fade()}
+ />
<div style={{ flex: 1, marginLeft: 10 }}>
<strong>
<code>{"fade()"}</code>
@@ -75,7 +78,10 @@ export const TableOfContents: React.FC = () => {
</TOCItem>
<TOCItem link="/docs/transitions/presentations/slide">
<div style={row}>
- <PresentationPreview effect={slide()} />
+ <PresentationPreview
+ durationRestThreshold={0.001}
+ effect={slide()}
+ />
<div style={{ flex: 1, marginLeft: 10 }}>
<strong>
<code>{"slide()"}</code>
@@ -86,7 +92,10 @@ export const TableOfContents: React.FC = () => {
</TOCItem>
<TOCItem link="/docs/transitions/presentations/wipe">
<div style={row}>
- <PresentationPreview effect={wipe()} />
+ <PresentationPreview
+ durationRestThreshold={0.001}
+ effect={wipe()}
+ />
<div style={{ flex: 1, marginLeft: 10 }}>
<strong>
<code>{"wipe()"}</code>
diff --git a/packages/docs/components/demos/index.tsx b/packages/docs/components/demos/index.tsx
index 29d5f9f985..0026df8459 100644
--- a/packages/docs/components/demos/index.tsx
+++ b/packages/docs/components/demos/index.tsx
@@ -18,6 +18,7 @@ import {
scaleDemo,
skewDemo,
slidePresentationDemo,
+ slidePresentationDemoLongThreshold,
starDemo,
translateDemo,
triangleDemo,
@@ -48,6 +49,7 @@ const demos: DemoType[] = [
fadePresentationDemo,
wipePresentationDemo,
slidePresentationDemo,
+ slidePresentationDemoLongThreshold,
customPresentationDemo,
];
diff --git a/packages/docs/components/demos/types.ts b/packages/docs/components/demos/types.ts
index da49e2cc4a..86a3e6d508 100644
--- a/packages/docs/components/demos/types.ts
+++ b/packages/docs/components/demos/types.ts
@@ -2,6 +2,7 @@ import {
CustomTransitionDemo,
FadeDemo,
SlideDemo,
+ SlideDemoLongDurationRest,
WipeDemo,
} from "../transitions/previews";
import { CircleDemo } from "./Circle";
@@ -506,6 +507,17 @@ export const slidePresentationDemo: DemoType = {
],
};
+export const slidePresentationDemoLongThreshold: DemoType = {
+ comp: SlideDemoLongDurationRest,
+ compHeight: 280,
+ compWidth: 540,
+ durationInFrames: 90,
+ fps: 30,
+ id: "slide-long-duration-rest",
+ autoPlay: true,
+ options: [],
+};
+
export const wipePresentationDemo: DemoType = {
comp: WipeDemo,
compHeight: 280,
diff --git a/packages/docs/components/transitions/previews.tsx b/packages/docs/components/transitions/previews.tsx
index 6a82d7b5ec..231ec70233 100644
--- a/packages/docs/components/transitions/previews.tsx
+++ b/packages/docs/components/transitions/previews.tsx
@@ -13,7 +13,8 @@ import { customPresentation } from "./custom-transition";
export const PresentationPreview: React.FC<{
effect: TransitionPresentation<Record<string, unknown>>;
-}> = ({ effect }) => {
+ durationRestThreshold: number;
+}> = ({ effect, durationRestThreshold }) => {
const ref = useRef<PlayerRef>(null);
useEffect(() => {
@@ -51,6 +52,7 @@ export const PresentationPreview: React.FC<{
}}
inputProps={{
effect,
+ durationRestThreshold,
}}
/>
);
@@ -94,7 +96,8 @@ const SceneB: React.FC = () => {
export const SampleTransition: React.FC<{
effect: TransitionPresentation<Record<string, unknown>>;
-}> = ({ effect }) => {
+ durationRestThreshold: number;
+}> = ({ durationRestThreshold, effect }) => {
return (
<TransitionSeries>
<TransitionSeries.Sequence durationInFrames={75}>
@@ -107,10 +110,10 @@ export const SampleTransition: React.FC<{
damping: 200,
},
durationInFrames: 60,
- durationRestThreshold: 0.001,
+ durationRestThreshold,
})}
/>
- <TransitionSeries.Sequence durationInFrames={60}>
+ <TransitionSeries.Sequence durationInFrames={90}>
<SceneB />
</TransitionSeries.Sequence>
</TransitionSeries>
@@ -118,23 +121,49 @@ export const SampleTransition: React.FC<{
};
export const FadeDemo: React.FC = () => {
- return <SampleTransition effect={fade()} />;
+ return <SampleTransition effect={fade()} durationRestThreshold={0.001} />;
};
export const SlideDemo: React.FC<{
direction: SlideDirection;
}> = ({ direction }) => {
- return <SampleTransition effect={slide({ direction })} />;
+ return (
+ <SampleTransition
+ effect={slide({ direction })}
+ durationRestThreshold={0.001}
+ />
+ );
+};
+
+export const SlideDemoLongDurationRest: React.FC<{
+ direction: SlideDirection;
+}> = ({ direction }) => {
+ return (
+ <SampleTransition
+ effect={slide({ direction })}
+ durationRestThreshold={0.005}
+ />
+ );
};
export const WipeDemo: React.FC<{
direction: WipeDirection;
}> = ({ direction }) => {
- return <SampleTransition effect={wipe({ direction })} />;
+ return (
+ <SampleTransition
+ effect={wipe({ direction })}
+ durationRestThreshold={0.001}
+ />
+ );
};
export const CustomTransitionDemo: React.FC<{}> = () => {
const { width, height } = useVideoConfig();
- return <SampleTransition effect={customPresentation({ height, width })} />;
+ return (
+ <SampleTransition
+ effect={customPresentation({ height, width })}
+ durationRestThreshold={0.001}
+ />
+ );
};
diff --git a/packages/docs/docs/transitions/timings/springtiming.mdx b/packages/docs/docs/transitions/timings/springtiming.mdx
index 48943674fd..710f72ca9a 100644
--- a/packages/docs/docs/transitions/timings/springtiming.mdx
+++ b/packages/docs/docs/transitions/timings/springtiming.mdx
@@ -3,4 +3,88 @@ crumb: "@remotion/transitions - Timings"
title: "springTiming()"
---
-Spring timing
+A timing function for [`<TransitionSeries>`](/docs/transitions/transitionseries) based on [`spring()`](/docs/spring).
+
+```tsx twoslash title="SlideTransition.tsx"
+import { AbsoluteFill } from "remotion";
+
+const Letter: React.FC<{
+ children: React.ReactNode;
+ color: string;
+}> = ({ children, color }) => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: color,
+ opacity: 0.9,
+ justifyContent: "center",
+ alignItems: "center",
+ fontSize: 200,
+ color: "white",
+ }}
+ >
+ {children}
+ </AbsoluteFill>
+ );
+};
+// ---cut---
+import { springTiming, TransitionSeries } from "@remotion/transitions";
+import { slide } from "@remotion/transitions/slide";
+
+const BasicTransition = () => {
+ return (
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={40}>
+ <Letter color="#0b84f3">A</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={slide()}
+ timing={springTiming({
+ config: {
+ damping: 200,
+ },
+ durationInFrames: 30,
+ durationRestThreshold: 0.001,
+ })}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="pink">B</Letter>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ );
+};
+```
+
+## API
+
+An object with the following properties:
+
+### `config`
+
+_optional_
+
+A spring `config`, see [`spring()`](/docs/spring).
+
+### `durationInFrames`
+
+_optional_
+
+Stretch the timing curve of the animation to a fixed duration.
+
+### `durationRestThreshold?`
+
+_optional_
+
+At which point the animation is considered to be finished. Defaults: `0.005`
+
+## Recommendation: Set a low duration rest threshold
+
+The default `durationRestThreshold` is `0.005` (same as `spring()`). This means that if the animations has progressed 99.5%, it is considered to be finished.
+For a transition, this can lead to a slightly noticeable cutoff of the animation:
+
+<Demo type="slide-long-duration-rest" />
+
+To avoid this, set a low `durationRestThreshold`, we recommend `0.001`.
+
+Consider that this will also increase the duration of the animation.
+If you set a fixed `durationInFrames`, the animation will feel faster because it for longer it is not considered to be finished.