Skip to content

🎥 Make videos programmatically with React

cool

Jonny Burgerbfc8f1bc5563
diff --git a/packages/convert/app/components/timing-editor/Canvas.tsx b/packages/convert/app/components/timing-editor/Canvas.tsx
index 81b8b2b00a..ecbe6334a5 100644
--- a/packages/convert/app/components/timing-editor/Canvas.tsx
+++ b/packages/convert/app/components/timing-editor/Canvas.tsx
@@ -1,7 +1,7 @@
import React, {useEffect, useMemo, useRef} from 'react';
+import {AnimationDuration} from './AnimationDuration';
import {draw, stopDrawing} from './draw';
import type {TimingConfig} from './types';
-import {AnimationDuration} from './AnimationDuration';
export const Canvas: React.FC<{
readonly width: number;
@@ -11,7 +11,15 @@ export const Canvas: React.FC<{
readonly duration: number;
readonly config: TimingConfig;
readonly fps: number;
-}> = ({height, width, draggedConfig, draggedDuration, config, duration, fps}) => {
+}> = ({
+ height,
+ width,
+ draggedConfig,
+ draggedDuration,
+ config,
+ duration,
+ fps,
+}) => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const canvasStyle: React.CSSProperties = useMemo(() => {
diff --git a/packages/convert/app/components/timing-editor/InterpolateEditor.tsx b/packages/convert/app/components/timing-editor/InterpolateEditor.tsx
index 8d815ac57e..08b7309434 100644
--- a/packages/convert/app/components/timing-editor/InterpolateEditor.tsx
+++ b/packages/convert/app/components/timing-editor/InterpolateEditor.tsx
@@ -6,9 +6,10 @@ import type {EasingType, InterpolateTimingConfig} from './types';
export const InterpolateEditor: React.FC<{
readonly config: InterpolateTimingConfig;
+ readonly onDragChange: (config: InterpolateTimingConfig) => void;
readonly onChange: (config: InterpolateTimingConfig) => void;
readonly onRelease: () => void;
-}> = ({config, onChange, onRelease}) => {
+}> = ({config, onDragChange, onRelease, onChange}) => {
return (
<>
<label
@@ -26,6 +27,7 @@ export const InterpolateEditor: React.FC<{
value={config.easing}
onChange={(e) => {
onChange({...config, easing: e.target.value as EasingType});
+ onRelease();
}}
style={{
padding: '8px 12px',
@@ -49,7 +51,7 @@ export const InterpolateEditor: React.FC<{
max={200}
value={[config.durationInFrames]}
onValueChange={(val) => {
- onChange({...config, durationInFrames: val[0]});
+ onDragChange({...config, durationInFrames: val[0]});
}}
onPointerUp={onRelease}
/>
@@ -58,13 +60,12 @@ export const InterpolateEditor: React.FC<{
toggleable={null}
value={config.durationInFrames}
/>
- <br />
<Slider
min={0}
max={400}
value={[config.delay]}
onValueChange={(val) => {
- onChange({...config, delay: val[0]});
+ onDragChange({...config, delay: val[0]});
}}
onPointerUp={onRelease}
/>
diff --git a/packages/convert/app/components/timing-editor/Sidebar.tsx b/packages/convert/app/components/timing-editor/Sidebar.tsx
index 2ab029aa1c..072a3cb3b6 100644
--- a/packages/convert/app/components/timing-editor/Sidebar.tsx
+++ b/packages/convert/app/components/timing-editor/Sidebar.tsx
@@ -10,9 +10,17 @@ export const Sidebar: React.FC<{
readonly config: TimingConfig;
readonly calculatedDurationInFrames: number;
readonly onModeChange: (mode: 'spring' | 'interpolate' | 'sine') => void;
+ readonly setDraggedConfig: (config: TimingConfig) => void;
readonly onChange: (config: TimingConfig) => void;
readonly onRelease: () => void;
-}> = ({config, calculatedDurationInFrames, onModeChange, onChange, onRelease}) => {
+}> = ({
+ config,
+ calculatedDurationInFrames,
+ onModeChange,
+ onChange,
+ setDraggedConfig,
+ onRelease,
+}) => {
return (
<div className="p-4 flex flex-col border-r border-[#242424] flex-1 w-full overflow-y-auto md:w-[400px] md:h-full md:flex-none">
<div className="font-brand font-bold text-xl mb-4">Timing Editor</div>
@@ -40,17 +48,22 @@ export const Sidebar: React.FC<{
<SpringEditor
config={config}
calculatedDurationInFrames={calculatedDurationInFrames}
- onChange={onChange}
+ onChange={setDraggedConfig}
onRelease={onRelease}
/>
) : config.type === 'interpolate' ? (
<InterpolateEditor
config={config}
- onChange={onChange}
+ onDragChange={setDraggedConfig}
onRelease={onRelease}
+ onChange={onChange}
/>
) : (
- <SineEditor config={config} onChange={onChange} onRelease={onRelease} />
+ <SineEditor
+ config={config}
+ onChange={setDraggedConfig}
+ onRelease={onRelease}
+ />
)}
<Spacing y={2} />
</div>
diff --git a/packages/convert/app/components/timing-editor/SineEditor.tsx b/packages/convert/app/components/timing-editor/SineEditor.tsx
index b2e5bffbad..a31d3e75a3 100644
--- a/packages/convert/app/components/timing-editor/SineEditor.tsx
+++ b/packages/convert/app/components/timing-editor/SineEditor.tsx
@@ -24,7 +24,6 @@ export const SineEditor: React.FC<{
toggleable={null}
value={config.durationInFrames}
/>
- <br />
<Slider
min={0.1}
max={2}
@@ -35,8 +34,11 @@ export const SineEditor: React.FC<{
}}
onPointerUp={onRelease}
/>
- <SliderLabel label="amplitude" toggleable={null} value={config.amplitude} />
- <br />
+ <SliderLabel
+ label="amplitude"
+ toggleable={null}
+ value={config.amplitude}
+ />
<Slider
min={0.1}
max={10}
@@ -47,8 +49,11 @@ export const SineEditor: React.FC<{
}}
onPointerUp={onRelease}
/>
- <SliderLabel label="frequency" toggleable={null} value={config.frequency} />
- <br />
+ <SliderLabel
+ label="frequency"
+ toggleable={null}
+ value={config.frequency}
+ />
<Slider
min={0}
max={100}
diff --git a/packages/convert/app/components/timing-editor/TimingEditor.tsx b/packages/convert/app/components/timing-editor/TimingEditor.tsx
index f58fcfd00c..e1f68cb871 100644
--- a/packages/convert/app/components/timing-editor/TimingEditor.tsx
+++ b/packages/convert/app/components/timing-editor/TimingEditor.tsx
@@ -31,10 +31,6 @@ export function TimingEditor() {
[],
);
- const onChange = useCallback((newConfig: TimingConfig) => {
- setDraggedConfig(newConfig);
- }, []);
-
const onRelease = useCallback(() => {
if (draggedConfig) {
setConfig(draggedConfig);
@@ -76,8 +72,9 @@ export function TimingEditor() {
config={currentConfig}
calculatedDurationInFrames={duration}
onModeChange={onModeChange}
- onChange={onChange}
+ setDraggedConfig={setDraggedConfig}
onRelease={onRelease}
+ onChange={setConfig}
/>
<div className="flex flex-col h-[300px] w-full border-b border-[#242424] md:h-auto md:flex-1 md:border-b-0">
<CanvasWrapper