Skip to content

🎥 Make videos programmatically with React

replay button

Jonny Burger43502eb917d6
diff --git a/packages/convert/app/components/timing-editor/Canvas.tsx b/packages/convert/app/components/timing-editor/Canvas.tsx
index ecbe6334a5..fc36727b93 100644
--- a/packages/convert/app/components/timing-editor/Canvas.tsx
+++ b/packages/convert/app/components/timing-editor/Canvas.tsx
@@ -11,6 +11,7 @@ export const Canvas: React.FC<{
readonly duration: number;
readonly config: TimingConfig;
readonly fps: number;
+ readonly replayKey: number;
}> = ({
height,
width,
@@ -19,6 +20,7 @@ export const Canvas: React.FC<{
config,
duration,
fps,
+ replayKey,
}) => {
const canvasRef = useRef<HTMLCanvasElement>(null);
@@ -65,6 +67,7 @@ export const Canvas: React.FC<{
width,
height,
durationLabel,
+ replayKey,
]);
return (
diff --git a/packages/convert/app/components/timing-editor/CanvasWrapper.tsx b/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
index 5b37c654ba..42140e3414 100644
--- a/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
+++ b/packages/convert/app/components/timing-editor/CanvasWrapper.tsx
@@ -9,7 +9,8 @@ export const CanvasWrapper: React.FC<{
readonly duration: number;
readonly config: TimingConfig;
readonly fps: number;
-}> = ({config, draggedConfig, draggedDuration, duration, fps}) => {
+ readonly replayKey: number;
+}> = ({config, draggedConfig, draggedDuration, duration, fps, replayKey}) => {
const outer = useRef<HTMLDivElement>(null);
const elementSize = PlayerInternals.useElementSize(outer, {
@@ -37,6 +38,7 @@ export const CanvasWrapper: React.FC<{
fps={fps}
height={elementSize.height * window.devicePixelRatio}
width={elementSize.width * window.devicePixelRatio}
+ replayKey={replayKey}
/>
) : null}
</div>
diff --git a/packages/convert/app/components/timing-editor/Sidebar.tsx b/packages/convert/app/components/timing-editor/Sidebar.tsx
index 3ec0f290eb..7c9cbee17a 100644
--- a/packages/convert/app/components/timing-editor/Sidebar.tsx
+++ b/packages/convert/app/components/timing-editor/Sidebar.tsx
@@ -13,6 +13,7 @@ export const Sidebar: React.FC<{
readonly setDraggedConfig: (config: TimingConfig) => void;
readonly onChange: (config: TimingConfig) => void;
readonly onRelease: () => void;
+ readonly onReplay: () => void;
}> = ({
config,
calculatedDurationInFrames,
@@ -20,6 +21,7 @@ export const Sidebar: React.FC<{
onChange,
setDraggedConfig,
onRelease,
+ onReplay,
}) => {
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">
@@ -67,6 +69,13 @@ export const Sidebar: React.FC<{
/>
)}
<Spacing y={2} />
+ <button
+ type="button"
+ onClick={onReplay}
+ className="mt-auto px-4 py-2 bg-[#0b84f3] text-white rounded-md font-brand font-medium hover:bg-[#0a75d9] transition-colors"
+ >
+ Replay
+ </button>
</div>
);
};
diff --git a/packages/convert/app/components/timing-editor/TimingEditor.tsx b/packages/convert/app/components/timing-editor/TimingEditor.tsx
index e1f68cb871..5b9eaad2a1 100644
--- a/packages/convert/app/components/timing-editor/TimingEditor.tsx
+++ b/packages/convert/app/components/timing-editor/TimingEditor.tsx
@@ -15,6 +15,11 @@ const fps = 60;
export function TimingEditor() {
const [config, setConfig] = useState<TimingConfig>(DEFAULT_SPRING_CONFIG);
const [draggedConfig, setDraggedConfig] = useState<TimingConfig | null>(null);
+ const [replayKey, setReplayKey] = useState(0);
+
+ const onReplay = useCallback(() => {
+ setReplayKey((k) => k + 1);
+ }, []);
const onModeChange = useCallback(
(mode: 'spring' | 'interpolate' | 'sine') => {
@@ -75,6 +80,7 @@ export function TimingEditor() {
setDraggedConfig={setDraggedConfig}
onRelease={onRelease}
onChange={setConfig}
+ onReplay={onReplay}
/>
<div className="flex flex-col h-[300px] w-full border-b border-[#242424] md:h-auto md:flex-1 md:border-b-0">
<CanvasWrapper
@@ -83,6 +89,7 @@ export function TimingEditor() {
draggedDuration={draggedDuration}
duration={duration}
fps={fps}
+ replayKey={replayKey}
/>
<div className="hidden md:flex flex-row justify-center">
<AnimationPreview animation="Scale" id="spring-scale" />