From b5f6d0eb73d84e65067e1c2b79ade78511916a6e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 22 May 2021 18:55:26 +0200 Subject: keyframes movable using react-spring --- pages/editor.tsx | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'pages') diff --git a/pages/editor.tsx b/pages/editor.tsx index 5f29ddf..e1e164a 100644 --- a/pages/editor.tsx +++ b/pages/editor.tsx @@ -1,5 +1,5 @@ import { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react'; -import { animated, useSpring } from 'react-spring'; +import { animated, useSpring, useSprings } from 'react-spring'; import { useDrag } from 'react-use-gesture'; import create from 'zustand'; import { loopSlide } from '../timeline'; @@ -52,15 +52,38 @@ var useFrame = create(set => ({ function TimelineEditor(props: { player: TimedVideoPlayer; }) { - var keyframes = props.player?.timeline?.slides.map((slide, index) => -
+ var timelineZoom = getTimelineZoom((st: any) => st.zoom); + + var keyframes: Array<{ + html: ReactNode; + id: string; + }> = []; + var [keyframeSprings, _keyframeSpringsAPI] = useSprings( + props.player?.timeline?.slides.length || 0, + i => ({ + frame: props.player.timeline.slides[i].frame, + config: { mass: 0.5, tension: 500, friction: 20 }, + }), + ); + props.player?.timeline?.slides.forEach((slide, index) => { + var id = 'frame' + index; + var html =
{slide.type == 'loop' ? : }
-
- ); + ; + + keyframes[index] = { + html, + id, + }; + }); var timelineLabels = useTimelineLabels((st: any) => st.labels); var setTimelineLabels = useTimelineLabels((st: any) => st.setLabels); @@ -68,8 +91,6 @@ function TimelineEditor(props: { // var frame = useFrame((st: any) => st.currentFrame); var setFrame = useFrame((st: any) => st.setFrame); - var timelineZoom = getTimelineZoom((st: any) => st.zoom); - useEffect(() => { props.player.addEventListener('TimedVideoPlayerOnFrame', (event: CustomEvent) => { setFrame(event.detail); @@ -212,9 +233,8 @@ function TimelineEditor(props: {
- {keyframes} -
+ children={keyframes.map(kf => kf.html)} + /> ; } -- cgit v1.2.3