Skip to content

Commit 50a3a34

Browse files
fix(studio): display absolute times in animation panel for clip-relative positions
Co-authored-by: Miguel Ángel <miguel07alm@protonmail.com>
1 parent d36d989 commit 50a3a34

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

packages/studio/src/components/editor/AnimationCard.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ function parseNumericOrString(raw: string): number | string {
237237

238238
interface AnimationCardProps {
239239
animation: GsapAnimation;
240+
elementStart?: number;
240241
defaultExpanded: boolean;
241242
onUpdateProperty: (animationId: string, property: string, value: number | string) => void;
242243
onUpdateMeta: (
@@ -265,6 +266,7 @@ interface AnimationCardProps {
265266
// fallow-ignore-next-line complexity
266267
export const AnimationCard = memo(function AnimationCard({
267268
animation,
269+
elementStart = 0,
268270
defaultExpanded,
269271
onUpdateProperty,
270272
onUpdateMeta,
@@ -342,9 +344,9 @@ export const AnimationCard = memo(function AnimationCard({
342344
(raw: string) => {
343345
const num = Number(raw);
344346
if (Number.isFinite(num) && num >= 0)
345-
onUpdateMeta(animation.id, { position: Math.max(0, num) });
347+
onUpdateMeta(animation.id, { position: Math.max(0, num - elementStart) });
346348
},
347-
[animation.id, onUpdateMeta],
349+
[animation.id, elementStart, onUpdateMeta],
348350
);
349351

350352
const [copied, setCopied] = useState(false);
@@ -354,10 +356,12 @@ export const AnimationCard = memo(function AnimationCard({
354356
const easeLabel = easeName.startsWith("custom(")
355357
? "Custom curve"
356358
: (EASE_LABELS[easeName] ?? easeName);
359+
const absolutePosition =
360+
typeof animation.position === "number" ? animation.position + elementStart : animation.position;
357361
const endTime =
358-
typeof animation.position === "number"
359-
? animation.position + (animation.duration ?? 0)
360-
: animation.position;
362+
typeof absolutePosition === "number"
363+
? absolutePosition + (animation.duration ?? 0)
364+
: absolutePosition;
361365

362366
const summary = useMemo(() => buildTweenSummary(animation), [animation]);
363367

@@ -375,9 +379,9 @@ export const AnimationCard = memo(function AnimationCard({
375379
{methodLabel}
376380
</span>
377381
<span className="text-[11px] font-medium text-neutral-400" title="When this effect plays">
378-
{typeof animation.position === "number"
379-
? `${parseFloat(animation.position.toFixed(3))}s`
380-
: animation.position}{" "}
382+
{typeof absolutePosition === "number"
383+
? `${parseFloat(absolutePosition.toFixed(3))}s`
384+
: absolutePosition}{" "}
381385
{typeof endTime === "number" ? `${parseFloat(endTime.toFixed(3))}s` : endTime}
382386
</span>
383387
<span className="ml-auto text-[10px] text-neutral-500" title={easeName}>
@@ -439,11 +443,11 @@ export const AnimationCard = memo(function AnimationCard({
439443
<MetricField
440444
label="Starts at"
441445
value={
442-
typeof animation.position === "string"
443-
? animation.position
444-
: String(parseFloat(Math.max(0, animation.position).toFixed(3)))
446+
typeof absolutePosition === "string"
447+
? absolutePosition
448+
: String(parseFloat(Math.max(0, absolutePosition).toFixed(3)))
445449
}
446-
suffix={typeof animation.position === "number" ? "s" : undefined}
450+
suffix={typeof absolutePosition === "number" ? "s" : undefined}
447451
tooltip="When this effect begins on the timeline"
448452
onCommit={commitPosition}
449453
/>

packages/studio/src/components/editor/GsapAnimationSection.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AnimationCard } from "./AnimationCard";
77

88
interface GsapAnimationSectionProps {
99
animations: GsapAnimation[];
10+
elementStart?: number;
1011
multipleTimelines?: boolean;
1112
unsupportedTimelinePattern?: boolean;
1213
onUpdateProperty: (animationId: string, property: string, value: number | string) => void;
@@ -36,6 +37,7 @@ interface GsapAnimationSectionProps {
3637

3738
export const GsapAnimationSection = memo(function GsapAnimationSection({
3839
animations,
40+
elementStart = 0,
3941
multipleTimelines,
4042
unsupportedTimelinePattern,
4143
onUpdateProperty,
@@ -75,6 +77,7 @@ export const GsapAnimationSection = memo(function GsapAnimationSection({
7577
<AnimationCard
7678
key={anim.id}
7779
animation={anim}
80+
elementStart={elementStart}
7881
defaultExpanded={index === 0}
7982
onUpdateProperty={onUpdateProperty}
8083
onUpdateMeta={onUpdateMeta}

packages/studio/src/components/editor/PropertyPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ export const PropertyPanel = memo(function PropertyPanel({
510510
onAddGsapAnimation && (
511511
<GsapAnimationSection
512512
animations={gsapAnimations}
513+
elementStart={elStart}
513514
multipleTimelines={gsapMultipleTimelines}
514515
unsupportedTimelinePattern={gsapUnsupportedTimelinePattern}
515516
onUpdateProperty={onUpdateGsapProperty}

0 commit comments

Comments
 (0)