xzdarcy / react-timeline-editor

react-timeline-editor is a react component used to quickly build a timeline animation editor.
https://zdarcy.com/
MIT License
284 stars 82 forks source link

Click and Drag Timeline Scroll #32

Open parabuzzle opened 1 year ago

parabuzzle commented 1 year ago

I'm trying to figure out a way of clicking and dragging the timeline left and right. It would be great if there was a callback prop for the timeline view similar to onClickTimeArea or onCursorDrag for the entire timeline.

parabuzzle commented 1 year ago

for now I've made the scroll bar more visible by increasing the size with this css:

.timeline-editor :hover::-webkit-scrollbar:horizontal {
  height: 20px !important;
}

.timeline-editor :hover::-webkit-scrollbar-thumb:horizontal {
  background: #333 !important;
  border-radius: 5px !important;
}

It would still be nice to have the click and drag feature. I noticed on a laptop with 2-finger scroll it works.. but a desktop with no horizontal scroll mouse features, the timeline can be a bit of a pain to work with.

marcoburrometo commented 9 months ago

I just did something like this in a POC test that I'm doing :)

          <div className="container"
             onMouseDown={() => {
                    draggingRef.current = true;
                    videoRef.current.getInternalPlayer().pause();
                }}
                onMouseUp={() => {
                    draggingRef.current = false;
                    videoRef.current.getInternalPlayer().play();
                }}
                onMouseLeave={() => {
                    draggingRef.current = false;
                }}
                onMouseMove={(e) => {
                    if (draggingRef.current) {
                        const newTime = timelineState.current.getTime() + e.movementX / (SCALEWIDTH / SCALE);
                        const left = newTime * (SCALEWIDTH / SCALE) - timelineState.current.target.clientWidth / 2;

                        console.log('......mouse drag????', newTime, e.movementX);

                        timelineState.current.setTime(newTime);
                        timelineState.current.setScrollLeft(left);
                        videoRef.current.seekTo(newTime);
                        setCurrentTime(newTime);
                        // setCurrentTime(currentTime + direction);
                    }
                }}