Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Defer timeline edge selection until release

JonnyBurgerb5baf84919b5
diff --git a/packages/example/e2e/timeline-right-edge.test.mts b/packages/example/e2e/timeline-right-edge.test.mts
index 263da6d76e..31a6d60b60 100644
--- a/packages/example/e2e/timeline-right-edge.test.mts
+++ b/packages/example/e2e/timeline-right-edge.test.mts
@@ -114,18 +114,48 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
'[data-timeline-marquee-item][title="Explicit fill cutoff"]',
);
await expect(rightEdgeLayer).toHaveCSS('opacity', '0.75');
- await rightEdgeLayer.locator('[title="Drag to change duration"]').click();
+ const rightEdgeHandle = rightEdgeLayer.locator(
+ '[title="Drag to change duration"]',
+ );
+
+ await rightEdgeHandle.hover();
+ await page.mouse.down();
+ try {
+ await expect(rightEdgeLayer).toHaveCSS('opacity', '0.75');
+ } finally {
+ await page.mouse.up();
+ }
+
await expect(rightEdgeLayer).toHaveCSS('opacity', '1');
const leftEdgeLayer = page.locator(
'[data-timeline-marquee-item][title="Solid cutoff"]',
);
await expect(leftEdgeLayer).toHaveCSS('opacity', '0.75');
- await leftEdgeLayer.locator('[title="Drag to trim start"]').click();
+ const leftEdgeHandle = leftEdgeLayer.locator(
+ '[title="Drag to trim start"]',
+ );
+ const leftEdgeHandleBox = await leftEdgeHandle.boundingBox();
+ if (leftEdgeHandleBox === null) {
+ throw new Error('Expected left timeline edge to have a bounding box');
+ }
+
+ await page.mouse.move(
+ leftEdgeHandleBox.x + leftEdgeHandleBox.width - 1,
+ leftEdgeHandleBox.y + leftEdgeHandleBox.height / 2,
+ );
+ await page.mouse.down();
+ try {
+ await expect(leftEdgeLayer).toHaveCSS('opacity', '0.75');
+ await expect(rightEdgeLayer).toHaveCSS('opacity', '1');
+ } finally {
+ await page.mouse.up();
+ }
+
await expect(leftEdgeLayer).toHaveCSS('opacity', '1');
await expect(rightEdgeLayer).toHaveCSS('opacity', '0.75');
- const dragWithMeta = async ({
+ const dragHandle = async ({
handle,
deltaX,
}: {
@@ -139,18 +169,19 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
);
}
- await page.keyboard.down('Meta');
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
- await page.mouse.move(
- box.x + box.width / 2 + deltaX,
- box.y + box.height / 2,
- {
- steps: 5,
- },
- );
- await page.mouse.up();
- await page.keyboard.up('Meta');
+ try {
+ await page.mouse.move(
+ box.x + box.width / 2 + deltaX,
+ box.y + box.height / 2,
+ {
+ steps: 5,
+ },
+ );
+ } finally {
+ await page.mouse.up();
+ }
};
const getSequenceNumberProp = (
@@ -174,10 +205,37 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
);
await rightResizeA.scrollIntoViewIfNeeded();
await rightResizeA.click();
- await dragWithMeta({
+ await expect(rightResizeA).toHaveCSS('opacity', '1');
+ await expect(rightResizeB).toHaveCSS('opacity', '0.75');
+ await dragHandle({
handle: rightResizeB.locator('[title="Drag to change duration"]'),
deltaX: -40,
});
+ await expect(rightResizeA).toHaveCSS('opacity', '1');
+ await expect(rightResizeB).toHaveCSS('opacity', '0.75');
+ await expect
+ .poll(() => {
+ const source = fs.readFileSync(rootFile, 'utf-8');
+ return [
+ getSequenceNumberProp(
+ source,
+ 'Explicit fill cutoff',
+ 'durationInFrames',
+ ),
+ getSequenceNumberProp(source, 'Duration cutoff', 'durationInFrames'),
+ ];
+ })
+ .toEqual([30, 9]);
+
+ await rightResizeB
+ .locator('[title="Drag to change duration"]')
+ .click({modifiers: ['Meta']});
+ await expect(rightResizeA).toHaveCSS('opacity', '1');
+ await expect(rightResizeB).toHaveCSS('opacity', '1');
+ await dragHandle({
+ handle: rightResizeB.locator('[title="Drag to change duration"]'),
+ deltaX: 40,
+ });
await expect
.poll(() => {
const source = fs.readFileSync(rootFile, 'utf-8');
@@ -190,7 +248,7 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
getSequenceNumberProp(source, 'Duration cutoff', 'durationInFrames'),
];
})
- .toEqual([24, 9]);
+ .toEqual([36, 15]);
const leftResizeA = page.locator(
'[data-timeline-marquee-item][title="Explicit composition match"]',
@@ -200,7 +258,50 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
);
await leftResizeA.scrollIntoViewIfNeeded();
await leftResizeA.click();
- await dragWithMeta({
+ await expect(leftResizeA).toHaveCSS('opacity', '1');
+ await expect(leftResizeB).toHaveCSS('opacity', '0.75');
+ await dragHandle({
+ handle: leftResizeB.locator('[title="Drag to trim start"]'),
+ deltaX: 40,
+ });
+ await expect(leftResizeA).toHaveCSS('opacity', '1');
+ await expect(leftResizeB).toHaveCSS('opacity', '0.75');
+ await expect
+ .poll(() => {
+ const source = fs.readFileSync(rootFile, 'utf-8');
+ const fromA = getSequenceNumberProp(
+ source,
+ 'Explicit composition match',
+ 'from',
+ );
+ const fromB = getSequenceNumberProp(
+ source,
+ 'Fill clipped before own cutoff',
+ 'from',
+ );
+ return [
+ fromA,
+ fromB,
+ getSequenceNumberProp(
+ source,
+ 'Explicit composition match',
+ 'durationInFrames',
+ ),
+ getSequenceNumberProp(
+ source,
+ 'Fill clipped before own cutoff',
+ 'durationInFrames',
+ ),
+ ];
+ })
+ .toEqual([null, 6, 180, 174]);
+
+ await leftResizeB
+ .locator('[title="Drag to trim start"]')
+ .click({modifiers: ['Meta']});
+ await expect(leftResizeA).toHaveCSS('opacity', '1');
+ await expect(leftResizeB).toHaveCSS('opacity', '1');
+ await dragHandle({
handle: leftResizeB.locator('[title="Drag to trim start"]'),
deltaX: 40,
});
@@ -232,7 +333,7 @@ export const E2eTestRoot = () => <Composition id="timeline-edges" component={Lay
),
];
})
- .toEqual([6, 6, 174, 174]);
+ .toEqual([6, 12, 174, 168]);
} finally {
await stopStudio();
}
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index b9e5055cad..84ff5111ea 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -3,14 +3,7 @@ import {
stringifySequenceExpandedRowKey,
stringifySequenceSubscriptionKey,
} from '@remotion/studio-shared';
-import React, {
- useCallback,
- useContext,
- useEffect,
- useRef,
- useState,
-} from 'react';
-import {flushSync} from 'react-dom';
+import React, {useCallback, useContext, useEffect, useRef} from 'react';
import type {
CanUpdateSequencePropStatus,
CanUpdateSequencePropStatusKeyframed,
@@ -45,12 +38,13 @@ import {
getTimelineSequenceSelectionKey,
shouldSelectTimelineRowOnPointerDown,
useCurrentTimelineSelectionStateAsRef,
- type TimelineSelectionInteraction,
type TimelineSelection,
+ type TimelineSelectionInteraction,
} from './TimelineSelection';
const HANDLE_INSET = 6;
const HANDLE_OUTSET = 8;
+const timelineSequenceEdgeDragThresholdPx = 4;
export const timelineSequenceFromDragSnapThresholdPx = 10;
const getTimelineSequenceEdgeSelectionInteraction = ({
@@ -1153,15 +1147,14 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const {previewServerState} = useContext(StudioServerConnectionCtx);
const currentSelection = useCurrentTimelineSelectionStateAsRef();
- const [dragging, setDragging] = useState(false);
+ const stopPointerSessionRef = useRef<(() => void) | null>(null);
const dragStateRef = useRef<{
initialClientX: number;
latestDeltaFrames: number;
didMove: boolean;
pxPerFrame: number;
pointerId: number;
- button: number;
- target: HTMLDivElement;
+ selectionInteraction: TimelineSelectionInteraction | null;
targets: readonly TimelineSequenceLeftEdgeDragTarget[];
} | null>(null);
@@ -1173,6 +1166,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
previewServerState,
overrideIdToNodePathMappings,
onDragEnd,
+ onSelect,
});
latestRef.current = {
nodePathInfo,
@@ -1182,6 +1176,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
previewServerState,
overrideIdToNodePathMappings,
onDragEnd,
+ onSelect,
};
const finishDrag = useCallback((commit: boolean) => {
@@ -1195,7 +1190,13 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
document.body.style.userSelect = '';
document.body.style.webkitUserSelect = '';
stopForcingSpecificCursor();
- setDragging(false);
+ if (
+ commit &&
+ !dragState.didMove &&
+ dragState.selectionInteraction !== null
+ ) {
+ latestRef.current.onSelect(dragState.selectionInteraction);
+ }
const {
setPropStatuses: latestSetPropStatuses,
@@ -1258,6 +1259,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
return;
}
+ e.stopPropagation();
+ e.preventDefault();
+
const selectionInteraction = getTimelineSequenceEdgeSelectionInteraction({
button: e.button,
selected,
@@ -1265,156 +1269,148 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
metaKey: e.metaKey,
ctrlKey: e.ctrlKey,
});
- if (selectionInteraction) {
- flushSync(() => onSelect(selectionInteraction));
- }
-
const pxPerFrame =
timelineDurationInFrames > 0
? (windowWidth - TIMELINE_PADDING * 2) / timelineDurationInFrames
: 0;
- if (pxPerFrame <= 0) {
- return;
- }
+ const canCalculateDelta = Number.isFinite(pxPerFrame) && pxPerFrame > 0;
const {
nodePathInfo: latestNodePathInfo,
overrideIdToNodePathMappings: latestOverrideIdsToNodePaths,
} = latestRef.current;
const {selectedItems: latestSelectedItems} = currentSelection.current;
- const targets = getTimelineSequenceLeftEdgeDragTargets({
- draggedNodePathInfo: latestNodePathInfo,
- selectedItems: latestSelectedItems,
- sequences: sequencesRef.current,
- overrideIdsToNodePaths: latestOverrideIdsToNodePaths,
- propStatuses: propStatusesRef.current,
- });
- if (targets === null || targets.length === 0) {
- return;
- }
+ const targets = canCalculateDelta
+ ? (getTimelineSequenceLeftEdgeDragTargets({
+ draggedNodePathInfo: latestNodePathInfo,
+ selectedItems: latestSelectedItems,
+ sequences: sequencesRef.current,
+ overrideIdsToNodePaths: latestOverrideIdsToNodePaths,
+ propStatuses: propStatusesRef.current,
+ }) ?? [])
+ : [];
- e.stopPropagation();
- e.preventDefault();
+ stopPointerSessionRef.current?.();
dragStateRef.current = {
initialClientX: e.clientX,
latestDeltaFrames: 0,
didMove: false,
- pxPerFrame,
+ pxPerFrame: canCalculateDelta ? pxPerFrame : 1,
pointerId: e.pointerId,
- button: e.button,
- target: e.currentTarget,
+ selectionInteraction,
targets,
};
- e.currentTarget.setPointerCapture?.(e.pointerId);
document.body.style.userSelect = 'none';
document.body.style.webkitUserSelect = 'none';
forceSpecificCursor('ew-resize');
- setDragging(true);
- },
- [
- currentSelection,
- onSelect,
- propStatusesRef,
- selected,
- sequencesRef,
- timelineDurationInFrames,
- windowWidth,
- ],
- );
- useEffect(() => {
- if (!dragging) {
- return;
- }
+ const onMove = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
- const onMove = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
+ const dx = pointerEvent.clientX - dragState.initialClientX;
+ const deltaFrames = Math.round(dx / dragState.pxPerFrame);
+ dragState.latestDeltaFrames = deltaFrames;
+ if (
+ Math.abs(dx) >= timelineSequenceEdgeDragThresholdPx ||
+ getTimelineSequenceLeftEdgeDragChanges({
+ targets: dragState.targets,
+ deltaFrames,
+ }).length > 0
+ ) {
+ dragState.didMove = true;
+ }
- const dx = e.clientX - dragState.initialClientX;
- const deltaFrames = Math.round(dx / dragState.pxPerFrame);
- dragState.latestDeltaFrames = deltaFrames;
- if (deltaFrames !== 0) {
- dragState.didMove = true;
- }
+ for (const target of dragState.targets) {
+ const nextValues = getTimelineSequenceLeftEdgeDragValues({
+ initialDuration: target.initialDuration,
+ initialFrom: target.initialFrom,
+ initialTrimBefore: target.initialTrimBefore,
+ deltaFrames,
+ playbackRate: target.playbackRate,
+ minimumDuration: target.minimumDuration,
+ });
+ if (target.positionField !== null) {
+ latestRef.current.setDragOverrides(
+ target.nodePath,
+ target.positionField,
+ Internals.makeStaticDragOverride(nextValues.from),
+ );
+ }
- for (const target of dragState.targets) {
- const nextValues = getTimelineSequenceLeftEdgeDragValues({
- initialDuration: target.initialDuration,
- initialFrom: target.initialFrom,
- initialTrimBefore: target.initialTrimBefore,
- deltaFrames,
- playbackRate: target.playbackRate,
- minimumDuration: target.minimumDuration,
- });
- if (target.positionField !== null) {
latestRef.current.setDragOverrides(
target.nodePath,
- target.positionField,
- Internals.makeStaticDragOverride(nextValues.from),
+ 'durationInFrames',
+ Internals.makeStaticDragOverride(nextValues.durationInFrames),
+ );
+ latestRef.current.setDragOverrides(
+ target.nodePath,
+ 'trimBefore',
+ Internals.makeStaticDragOverride(nextValues.trimBefore),
);
}
+ };
- latestRef.current.setDragOverrides(
- target.nodePath,
- 'durationInFrames',
- Internals.makeStaticDragOverride(nextValues.durationInFrames),
- );
- latestRef.current.setDragOverrides(
- target.nodePath,
- 'trimBefore',
- Internals.makeStaticDragOverride(nextValues.trimBefore),
- );
- }
- };
-
- const onUp = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
+ const onUp = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
- // Include the release position even if the final pointermove was skipped.
- onMove(e);
- finishDrag(true);
- };
+ // Include the release position even if the final pointermove was skipped.
+ onMove(pointerEvent);
+ finishDrag(true);
+ };
- const onCancel = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
+ const onCancel = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
- finishDrag(false);
- };
+ finishDrag(false);
+ };
- const activeDragState = dragStateRef.current;
- if (!activeDragState) {
- return;
- }
+ stopPointerSessionRef.current = startCapturedPointerSession({
+ event: e.nativeEvent,
+ captureTarget: e.currentTarget,
+ onMove,
+ onEnd: (reason, endEvent) => {
+ stopPointerSessionRef.current = null;
+ if (
+ (reason === 'pointerup' ||
+ reason === 'buttons-released' ||
+ (reason === 'lostpointercapture' && endEvent?.buttons === 0)) &&
+ endEvent
+ ) {
+ onUp(endEvent);
+ } else if (endEvent) {
+ onCancel(endEvent);
+ } else {
+ finishDrag(false);
+ }
+ },
+ });
+ },
+ [
+ currentSelection,
+ finishDrag,
+ propStatusesRef,
+ selected,
+ sequencesRef,
+ timelineDurationInFrames,
+ windowWidth,
+ ],
+ );
- return startCapturedPointerSession({
- event: activeDragState,
- captureTarget: activeDragState.target,
- onMove,
- onEnd: (reason, endEvent) => {
- if (
- (reason === 'pointerup' ||
- reason === 'buttons-released' ||
- (reason === 'lostpointercapture' && endEvent?.buttons === 0)) &&
- endEvent
- ) {
- onUp(endEvent);
- } else if (endEvent) {
- onCancel(endEvent);
- } else {
- finishDrag(false);
- }
- },
- });
- }, [dragging, finishDrag]);
+ useEffect(() => {
+ return () => {
+ stopPointerSessionRef.current?.();
+ stopPointerSessionRef.current = null;
+ };
+ }, []);
const style: React.CSSProperties = {
...baseStyle,
@@ -1751,15 +1747,14 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
const {previewServerState} = useContext(StudioServerConnectionCtx);
const currentSelection = useCurrentTimelineSelectionStateAsRef();
- const [dragging, setDragging] = useState(false);
+ const stopPointerSessionRef = useRef<(() => void) | null>(null);
const dragStateRef = useRef<{
initialClientX: number;
latestDeltaFrames: number;
didMove: boolean;
pxPerFrame: number;
pointerId: number;
- button: number;
- target: HTMLDivElement;
+ selectionInteraction: TimelineSelectionInteraction | null;
targets: readonly TimelineSequenceDurationDragTarget[];
} | null>(null);
@@ -1772,6 +1767,7 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
previewServerState,
overrideIdToNodePathMappings,
onDragEnd,
+ onSelect,
});
latestRef.current = {
nodePathInfo,
@@ -1781,6 +1777,7 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
previewServerState,
overrideIdToNodePathMappings,
onDragEnd,
+ onSelect,
};
const finishDrag = useCallback((commit: boolean) => {
@@ -1794,7 +1791,13 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
document.body.style.userSelect = '';
document.body.style.webkitUserSelect = '';
stopForcingSpecificCursor();
- setDragging(false);
+ if (
+ commit &&
+ !dragState.didMove &&
+ dragState.selectionInteraction !== null
+ ) {
+ latestRef.current.onSelect(dragState.selectionInteraction);
+ }
const {
setPropStatuses: latestSetPropStatuses,
@@ -1855,6 +1858,9 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
return;
}
+ e.stopPropagation();
+ e.preventDefault();
+
const selectionInteraction = getTimelineSequenceEdgeSelectionInteraction({
button: e.button,
selected,
@@ -1862,55 +1868,119 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
metaKey: e.metaKey,
ctrlKey: e.ctrlKey,
});
- if (selectionInteraction) {
- flushSync(() => onSelect(selectionInteraction));
- }
-
const pxPerFrame =
timelineDurationInFrames > 0
? (windowWidth - TIMELINE_PADDING * 2) / timelineDurationInFrames
: 0;
- if (pxPerFrame <= 0) {
- return;
- }
+ const canCalculateDelta = Number.isFinite(pxPerFrame) && pxPerFrame > 0;
const {
nodePathInfo: latestNodePathInfo,
overrideIdToNodePathMappings: latestOverrideIdsToNodePaths,
} = latestRef.current;
const {selectedItems: latestSelectedItems} = currentSelection.current;
- const targets = getTimelineSequenceDurationDragTargets({
- draggedNodePathInfo: latestNodePathInfo,
- selectedItems: latestSelectedItems,
- sequences: sequencesRef.current,
- overrideIdsToNodePaths: latestOverrideIdsToNodePaths,
- propStatuses: propStatusesRef.current,
- });
- if (targets === null || targets.length === 0) {
- return;
- }
+ const targets = canCalculateDelta
+ ? (getTimelineSequenceDurationDragTargets({
+ draggedNodePathInfo: latestNodePathInfo,
+ selectedItems: latestSelectedItems,
+ sequences: sequencesRef.current,
+ overrideIdsToNodePaths: latestOverrideIdsToNodePaths,
+ propStatuses: propStatusesRef.current,
+ }) ?? [])
+ : [];
- e.stopPropagation();
- e.preventDefault();
+ stopPointerSessionRef.current?.();
dragStateRef.current = {
initialClientX: e.clientX,
latestDeltaFrames: 0,
didMove: false,
- pxPerFrame,
+ pxPerFrame: canCalculateDelta ? pxPerFrame : 1,
pointerId: e.pointerId,
- button: e.button,
- target: e.currentTarget,
+ selectionInteraction,
targets,
};
- e.currentTarget.setPointerCapture?.(e.pointerId);
document.body.style.userSelect = 'none';
document.body.style.webkitUserSelect = 'none';
forceSpecificCursor('ew-resize');
- setDragging(true);
+
+ const onMove = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
+
+ const dx = pointerEvent.clientX - dragState.initialClientX;
+ const deltaFrames = Math.round(dx / dragState.pxPerFrame);
+ dragState.latestDeltaFrames = deltaFrames;
+ if (
+ Math.abs(dx) >= timelineSequenceEdgeDragThresholdPx ||
+ getTimelineSequenceDurationDragChanges({
+ targets: dragState.targets,
+ deltaFrames,
+ }).length > 0
+ ) {
+ dragState.didMove = true;
+ }
+
+ for (const target of dragState.targets) {
+ latestRef.current.setDragOverrides(
+ target.nodePath,
+ 'durationInFrames',
+ Internals.makeStaticDragOverride(
+ getTimelineSequenceDurationDragValue({
+ initialDuration: target.initialDuration,
+ deltaFrames,
+ minimumDuration: target.minimumDuration,
+ }),
+ ),
+ );
+ }
+ };
+
+ const onUp = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
+
+ // Include the release position even if the final pointermove was skipped.
+ onMove(pointerEvent);
+ finishDrag(true);
+ };
+
+ const onCancel = (pointerEvent: PointerEvent) => {
+ const dragState = dragStateRef.current;
+ if (!dragState || pointerEvent.pointerId !== dragState.pointerId) {
+ return;
+ }
+
+ finishDrag(false);
+ };
+
+ stopPointerSessionRef.current = startCapturedPointerSession({
+ event: e.nativeEvent,
+ captureTarget: e.currentTarget,
+ onMove,
+ onEnd: (reason, endEvent) => {
+ stopPointerSessionRef.current = null;
+ if (
+ (reason === 'pointerup' ||
+ reason === 'buttons-released' ||
+ (reason === 'lostpointercapture' && endEvent?.buttons === 0)) &&
+ endEvent
+ ) {
+ onUp(endEvent);
+ } else if (endEvent) {
+ onCancel(endEvent);
+ } else {
+ finishDrag(false);
+ }
+ },
+ });
},
[
currentSelection,
- onSelect,
+ finishDrag,
propStatusesRef,
selected,
sequencesRef,
@@ -1919,87 +1989,12 @@ const TimelineSequenceRightEdgeDragHandleInner: React.FC<{
],
);
- // Install global pointer listeners while dragging. They survive parent re-renders
- // and element remounts that would otherwise drop React's synthetic handlers or
- // pointer capture.
useEffect(() => {
- if (!dragging) {
- return;
- }
-
- const onMove = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
-
- const dx = e.clientX - dragState.initialClientX;
- const deltaFrames = Math.round(dx / dragState.pxPerFrame);
- dragState.latestDeltaFrames = deltaFrames;
- if (deltaFrames !== 0) {
- dragState.didMove = true;
- }
-
- for (const target of dragState.targets) {
- latestRef.current.setDragOverrides(
- target.nodePath,
- 'durationInFrames',
- Internals.makeStaticDragOverride(
- getTimelineSequenceDurationDragValue({
- initialDuration: target.initialDuration,
- deltaFrames,
- minimumDuration: target.minimumDuration,
- }),
- ),
- );
- }
- };
-
- const onUp = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
-
- // Include the release position even if the final pointermove was skipped.
- onMove(e);
- finishDrag(true);
- };
-
- const onCancel = (e: PointerEvent) => {
- const dragState = dragStateRef.current;
- if (!dragState || e.pointerId !== dragState.pointerId) {
- return;
- }
-
- finishDrag(false);
+ return () => {
+ stopPointerSessionRef.current?.();
+ stopPointerSessionRef.current = null;
};
-
- const activeDragState = dragStateRef.current;
- if (!activeDragState) {
- return;
- }
-
- return startCapturedPointerSession({
- event: activeDragState,
- captureTarget: activeDragState.target,
- onMove,
- onEnd: (reason, endEvent) => {
- if (
- (reason === 'pointerup' ||
- reason === 'buttons-released' ||
- (reason === 'lostpointercapture' && endEvent?.buttons === 0)) &&
- endEvent
- ) {
- onUp(endEvent);
- } else if (endEvent) {
- onCancel(endEvent);
- } else {
- finishDrag(false);
- }
- },
- });
- }, [dragging, finishDrag]);
+ }, []);
const style: React.CSSProperties = {
...baseStyle,