Skip to content

🎥 Make videos programmatically with React

fix(studio): explain computed timeline trim values

JonnyBurger5b322e7cf62a
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index 4a27b624c0..a356b2a094 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -1810,13 +1810,37 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
validatedLocation !== null &&
durationCanResize &&
(!isMedia || Boolean(s.loopDisplay) || mediaDurationDragLimits !== null);
+ const leftTrimStatuses = isCascadingSequence(s)
+ ? [
+ propStatusesForOverride?.durationInFrames,
+ propStatusesForOverride?.trimBefore,
+ ]
+ : [
+ propStatusesForOverride?.from,
+ propStatusesForOverride?.durationInFrames,
+ propStatusesForOverride?.trimBefore,
+ ];
+ const leftTrimBlockedReason =
+ previewInteractive &&
+ leftTrimStatuses.some((status) => status?.status === 'computed') &&
+ leftTrimStatuses.every(
+ (status) => status?.status === 'static' || status?.status === 'computed',
+ )
+ ? ('Computed value' as const)
+ : null;
+ const sourceTrimBlockedReason =
+ previewInteractive &&
+ propStatusesForOverride?.trimBefore?.status === 'computed'
+ ? ('Computed value' as const)
+ : null;
const showLeftEdgeDragHandle =
isTimelineSequenceLeftEdgeDraggable(s) &&
nodePath !== null &&
validatedLocation !== null &&
- (isCascadingSequence(s)
+ ((isCascadingSequence(s)
? durationCanUpdate && trimBeforeCanUpdate
- : fromCanUpdate && durationCanUpdate && trimBeforeCanUpdate);
+ : fromCanUpdate && durationCanUpdate && trimBeforeCanUpdate) ||
+ leftTrimBlockedReason !== null);
const canRoll = (previous: TSequence | null, next: TSequence | null) => {
if (!previewInteractive || !previous || !next) return false;
return [previous, next].every((sequence) => {
@@ -1890,6 +1914,8 @@ const useTimelineSequenceState = (props: TimelineSequenceProps) => {
hasCaptionsSchema,
showRightEdgeDragHandle,
showLeftEdgeDragHandle,
+ leftTrimBlockedReason,
+ sourceTrimBlockedReason,
onPointerEnter,
};
};
@@ -1971,6 +1997,8 @@ const TimelineSequenceLayoutInner: React.FC<{
hasCaptionsSchema,
showRightEdgeDragHandle,
showLeftEdgeDragHandle,
+ leftTrimBlockedReason,
+ sourceTrimBlockedReason,
onPointerEnter,
} = state;
const sceneRange = useContext(TimelineSceneRangeContext);
@@ -2352,7 +2380,7 @@ const TimelineSequenceLayoutInner: React.FC<{
isTimelineSequenceLeftEdgeDraggable(s) &&
nodePath !== null &&
validatedLocation !== null &&
- trimBeforeCanUpdate;
+ (trimBeforeCanUpdate || sourceTrimBlockedReason !== null);
const secondaryLeftEdgeAction = canShowSecondaryLeftEdgeAction
? 'source-only'
: null;
@@ -2493,6 +2521,8 @@ const TimelineSequenceLayoutInner: React.FC<{
trimBeforeCursor={`${timelineLeftEdgeCursor}, e-resize`}
sourceOnlyCursor={`${timelineSourceOnlyCursor}, ew-resize`}
edgeEnabled={leftTrimEnabled}
+ edgeBlockedReason={leftTrimBlockedReason}
+ sourceTrimBlockedReason={sourceTrimBlockedReason}
handleLayout={trimHandleLayout}
edgeOffset={leftEdgeOffset}
edgeMode={
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index 0f80843f6c..022954a3af 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -1971,6 +1971,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
readonly trimBeforeCursor: string;
readonly sourceOnlyCursor: string;
readonly edgeEnabled: boolean;
+ readonly edgeBlockedReason: TimelineTrimLimitReason | null;
+ readonly sourceTrimBlockedReason: TimelineTrimLimitReason | null;
readonly edgeMode: TimelineSequenceLeftEdgeDragMode;
readonly rollingEnabled: boolean;
readonly handleLayout: ReturnType<typeof getTimelineTrimHandleLayout>;
@@ -1998,6 +2000,8 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
trimBeforeCursor,
sourceOnlyCursor,
edgeEnabled,
+ edgeBlockedReason,
+ sourceTrimBlockedReason,
edgeMode,
rollingEnabled,
handleLayout,
@@ -2175,6 +2179,11 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const mode = e.currentTarget.dataset
.trimMode as TimelineSequenceLeftEdgeDragMode;
const trimBeforeOnly = mode === 'source-only';
+ const blockedReason = trimBeforeOnly
+ ? sourceTrimBlockedReason
+ : mode === edgeMode
+ ? edgeBlockedReason
+ : null;
const activeCursor =
mode === 'ripple' || mode === 'rolling'
? cursor
@@ -2219,7 +2228,7 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const initialTimelineEdge = latestRef.current.initialEdgeFrame;
const getTargets = (statuses: PropStatuses) =>
- canCalculateDelta
+ canCalculateDelta && blockedReason === null
? ((mode === 'rolling'
? getTimelineSequenceRollingEditTargets({
draggedNodePathInfo: latestNodePathInfo,
@@ -2251,19 +2260,23 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
finishDrag(false);
},
onStart: () => {
- const preparedPropStatuses = getKeyframeTrimConstraints({
- propStatuses,
- overrideIdsToNodePaths,
- sequences,
- affectedNodePaths: getTargets(propStatuses).flatMap((target) =>
- target.ripplePrevious
- ? target.positionField === null &&
- target.rollingDuration === null
- ? [target.ripplePrevious.nodePath]
- : [target.nodePath, target.ripplePrevious.nodePath]
- : [target.nodePath],
- ),
- });
+ const preparedPropStatuses =
+ blockedReason === null
+ ? getKeyframeTrimConstraints({
+ propStatuses,
+ overrideIdsToNodePaths,
+ sequences,
+ affectedNodePaths: getTargets(propStatuses).flatMap(
+ (target) =>
+ target.ripplePrevious
+ ? target.positionField === null &&
+ target.rollingDuration === null
+ ? [target.ripplePrevious.nodePath]
+ : [target.nodePath, target.ripplePrevious.nodePath]
+ : [target.nodePath],
+ ),
+ })
+ : propStatuses;
const targets = getTargets(preparedPropStatuses);
const draggedKey = stringifySequenceSubscriptionKey(
latestNodePathInfo.sequenceSubscriptionKey,
@@ -2276,8 +2289,10 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
) ?? (fillTarget ? targets[0] : undefined);
onDragStart(
mode,
- true,
- targets.map((target) => target.nodePath),
+ blockedReason === null,
+ blockedReason === null
+ ? targets.map((target) => target.nodePath)
+ : [latestNodePathInfo.sequenceSubscriptionKey],
);
dragStateRef.current = {
@@ -2299,6 +2314,16 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
document.body.style.userSelect = 'none';
document.body.style.webkitUserSelect = 'none';
forceSpecificCursor(activeCursor);
+ if (blockedReason !== null) {
+ latestRef.current.onLimitChange(true);
+ setTrimTooltip({
+ limitReason: blockedReason,
+ deltaFrames: 0,
+ edgeFrame: initialTimelineEdge,
+ x: initialEdgeClientX,
+ y: initialEdgeClientY,
+ });
+ }
const onMove = (pointerEvent: PointerEvent) => {
const dragState = dragStateRef.current;
@@ -2307,6 +2332,12 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
}
const dx = pointerEvent.clientX - dragState.initialClientX;
+ if (blockedReason !== null) {
+ dragState.didMove ||=
+ Math.abs(dx) >= timelineSequenceEdgeDragThresholdPx;
+ return;
+ }
+
if (
isTransitionSeries &&
!dragState.didMove &&
@@ -2624,6 +2655,9 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
fillTarget,
edgeOffset,
isTransitionSeries,
+ edgeMode,
+ edgeBlockedReason,
+ sourceTrimBlockedReason,
],
);
@@ -2652,6 +2686,13 @@ const TimelineSequenceLeftEdgeDragHandleInner: React.FC<{
const onHover = (mode: TimelineSequenceLeftEdgeDragMode) => {
if (dragStateRef.current === null) {
onDragStart(mode, false, [nodePathInfo.sequenceSubscriptionKey]);
+ onLimitChange(
+ (mode === 'source-only'
+ ? sourceTrimBlockedReason
+ : mode === edgeMode
+ ? edgeBlockedReason
+ : null) !== null,
+ );
}
};
diff --git a/packages/studio/src/components/Timeline/timeline-trim-limit-reason.ts b/packages/studio/src/components/Timeline/timeline-trim-limit-reason.ts
index 81cd555308..132f283623 100644
--- a/packages/studio/src/components/Timeline/timeline-trim-limit-reason.ts
+++ b/packages/studio/src/components/Timeline/timeline-trim-limit-reason.ts
@@ -1,6 +1,7 @@
export const TIMELINE_TRIM_LIMIT_REASONS = [
'Keyframe constraint',
'Computed keyframes',
+ 'Computed value',
'Unknown media duration',
'Minimum duration',
'Transition limit',
@@ -21,6 +22,7 @@ export const getVisibleTimelineTrimLimitReason = (
): TimelineTrimLimitReason | null => {
return reason === 'Keyframe constraint' ||
reason === 'Computed keyframes' ||
+ reason === 'Computed value' ||
reason === 'Unknown media duration' ||
reason === 'Transition limit'
? reason