Skip to content

🎥 Make videos programmatically with React

better drag and drop

Jonny Burger12fe2ded5359
diff --git a/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx b/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
index 69926fe7c0..4a3077d4f3 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineDragHandler.tsx
@@ -5,6 +5,7 @@ import {useGetXPositionOfItemInTimeline} from '../../helpers/get-left-of-timelin
import {TIMELINE_PADDING} from '../../helpers/timeline-layout';
import {persistCurrentFrame} from '../FramePersistor';
import {sliderAreaRef} from './timeline-refs';
+import {inMarkerAreaRef, outMarkerAreaRef} from './TimelineInOutPointer';
import {
inPointerHandle,
outPointerHandle,
@@ -155,6 +156,10 @@ export const TimelineDragHandler: React.FC = () => {
throw new Error('in pointer handle');
}
+ if (!inMarkerAreaRef.current) {
+ throw new Error('expected inMarkerAreaRef');
+ }
+
if (!inFrame) {
throw new Error('expected inframes');
}
@@ -163,6 +168,8 @@ export const TimelineDragHandler: React.FC = () => {
inPointerHandle.current.style.transform = `translateX(${
get(inFrame) + offset
}px)`;
+ inMarkerAreaRef.current.style.width =
+ String(get(inFrame) + offset) + 'px';
}
if (inOutDragging.dragging === 'out') {
@@ -170,6 +177,10 @@ export const TimelineDragHandler: React.FC = () => {
throw new Error('in pointer handle');
}
+ if (!outMarkerAreaRef.current) {
+ throw new Error('in outMarkerAreaRef');
+ }
+
if (!outFrame) {
throw new Error('expected outframes');
}
@@ -178,9 +189,13 @@ export const TimelineDragHandler: React.FC = () => {
outPointerHandle.current.style.transform = `translateX(${
get(outFrame) + offset
}px)`;
+ outMarkerAreaRef.current.style.left =
+ String(get(outFrame) + offset) + 'px';
+ outMarkerAreaRef.current.style.width =
+ String(width - get(outFrame) - offset) + 'px';
}
},
- [get, inFrame, inOutDragging, outFrame, videoConfig]
+ [get, inFrame, inOutDragging, outFrame, videoConfig, width]
);
const onPointerUpScrubbing = useCallback(
diff --git a/packages/cli/src/editor/components/Timeline/TimelineInOutPointer.tsx b/packages/cli/src/editor/components/Timeline/TimelineInOutPointer.tsx
index b15d6f7f97..fac648ae0a 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineInOutPointer.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineInOutPointer.tsx
@@ -1,5 +1,5 @@
import {PlayerInternals} from '@remotion/player';
-import React, {useEffect} from 'react';
+import React, {createRef, useEffect} from 'react';
import {Internals} from 'remotion';
import {useGetXPositionOfItemInTimeline} from '../../helpers/get-left-of-timeline-slider';
@@ -11,6 +11,9 @@ const areaHighlight: React.CSSProperties = {
top: 0,
};
+export const inMarkerAreaRef = createRef<HTMLDivElement>();
+export const outMarkerAreaRef = createRef<HTMLDivElement>();
+
export const TimelineInOutPointer: React.FC = () => {
const timelinePosition = Internals.Timeline.useTimelinePosition();
const {
@@ -43,6 +46,7 @@ export const TimelineInOutPointer: React.FC = () => {
<>
{inFrame !== null && (
<div
+ ref={inMarkerAreaRef}
style={{
...areaHighlight,
left: 0,
@@ -53,6 +57,7 @@ export const TimelineInOutPointer: React.FC = () => {
{outFrame !== null && (
<div
+ ref={outMarkerAreaRef}
style={{
...areaHighlight,
left: get(outFrame),