Skip to content

Commit b18fd62

Browse files
committed
fix(studio): keep an animated element on the drop point when resized
An element whose position is animated left the drop point anyway. The finalize step wrote its correction as a static position hold, and the element's position tween rendered its own value a frame later and won. Before that it stood down entirely on such elements, on the grounds that a keyframed path has no single anchor to preserve, which had the same visible result: the element moved. It has an anchor, the frame the user is looking at. The correction now goes into that tween at the playhead, through commitGsapPositionFromDrag, which is the same commit a drag on the same element already uses. Static holds keep the existing path. This is the difference the debug log showed between an element carrying position:to, which moved after release, and one carrying position:set, which did not.
1 parent 7dc1877 commit b18fd62

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

‎packages/studio/src/hooks/gsapResizeIntercept.ts‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import {
2727
import type { GsapDragCommitCallbacks } from "./gsapDragCommit";
2828
import { pickClosestToPlayhead, readGsapPositionFromIframe } from "./gsapPositionDetection";
2929
import { commitWholePropertyOffset } from "./gsapWholePropertyOffsetCommit";
30+
import { commitGsapPositionFromDrag } from "./gsapDragPositionCommit";
3031
import { resolveTweenStart, resolveTweenDuration } from "../utils/globalTimeCompiler";
3132
import { isInstantHold, selectorFromSelection, writeTargetSelector } from "./gsapShared";
3233
import { roundTo3 } from "../utils/rounding";
33-
import { resolveGroupTween, POSITION_CHANNELS } from "./gsapRuntimeBridge";
34-
import { hasNonHoldTweenForElement } from "./gsapRuntimeKeyframes";
34+
import { resolveGroupTween } from "./gsapRuntimeBridge";
3535
import { logResize } from "../utils/resizeDebug";
3636
import {
3737
animationWritesAnyProperty,
@@ -286,16 +286,6 @@ export async function tryGsapResizeIntercept(
286286
if (!scaleDraftEl) return;
287287
clearStudioBoxSize(scaleDraftEl);
288288
if (!scaleDraftDropPoint || !selector) return;
289-
const hasLivePositionTween = hasNonHoldTweenForElement(
290-
iframe,
291-
selector,
292-
undefined,
293-
POSITION_CHANNELS,
294-
);
295-
if (hasLivePositionTween) {
296-
logResize("scale-finalize", { skipped: "live-position-tween" });
297-
return;
298-
}
299289
// Put the committed scale on the live element before measuring.
300290
//
301291
// This step reads where the commit lands the box and shifts the position
@@ -348,20 +338,34 @@ export async function tryGsapResizeIntercept(
348338
const currentAnimations = fetchFallbackAnimations
349339
? await fetchFallbackAnimations()
350340
: (resolved?.animations ?? animations);
351-
const existingSet = findExistingPositionWrite(currentAnimations, selector, selection.element);
352341
// Delta chosen so the drag-path math composes back to exactly `corrected`
353342
// (no drag scratch attrs exist during a resize, so base = gsapPos).
354-
await commitStaticGsapPosition(
355-
selection,
356-
{ x: corrected.x - gsapPos.x, y: corrected.y - gsapPos.y },
357-
gsapPos,
358-
selector,
359-
existingSet,
360-
{
343+
const delta = { x: corrected.x - gsapPos.x, y: corrected.y - gsapPos.y };
344+
// An element whose position is animated needs the correction written into
345+
// that animation, at the playhead, or the tween renders its own value a
346+
// frame later and the element leaves the drop point anyway. This used to
347+
// stand down here instead, on the grounds that a keyframed path has no
348+
// single anchor to preserve. It has one: the frame the user is looking at.
349+
// Writing it is the same thing a drag on the same element does, through
350+
// the same commit.
351+
const positionTween = pickClosestToPlayhead(
352+
currentAnimations.filter(
353+
(a) => a.propertyGroup === "position" && !isInstantHold(a) && resolveTweenDuration(a) > 0,
354+
),
355+
);
356+
if (positionTween) {
357+
logResize("scale-finalize", { route: "position-keyframe", tweenId: positionTween.id });
358+
await commitGsapPositionFromDrag(selection, positionTween, delta, gsapPos, iframe, selector, {
361359
commitMutation,
362360
fetchAnimations: fetchFallbackAnimations,
363-
},
364-
);
361+
});
362+
return;
363+
}
364+
const existingSet = findExistingPositionWrite(currentAnimations, selector, selection.element);
365+
await commitStaticGsapPosition(selection, delta, gsapPos, selector, existingSet, {
366+
commitMutation,
367+
fetchAnimations: fetchFallbackAnimations,
368+
});
365369
};
366370

367371
// With auto-keyframe off (#1808), `anim` is already a real (non-"set")

0 commit comments

Comments
 (0)