fix: respect scale lock when editing keyframed scale
This commit is contained in:
parent
e43b859439
commit
f47e85c3bb
|
|
@ -21,6 +21,7 @@ export function useKeyframedNumberProperty({
|
||||||
valueAtPlayhead,
|
valueAtPlayhead,
|
||||||
step,
|
step,
|
||||||
buildBaseUpdates,
|
buildBaseUpdates,
|
||||||
|
buildAdditionalKeyframes,
|
||||||
}: {
|
}: {
|
||||||
trackId: string;
|
trackId: string;
|
||||||
elementId: string;
|
elementId: string;
|
||||||
|
|
@ -33,6 +34,9 @@ export function useKeyframedNumberProperty({
|
||||||
valueAtPlayhead: number;
|
valueAtPlayhead: number;
|
||||||
step?: number;
|
step?: number;
|
||||||
buildBaseUpdates: ({ value }: { value: number }) => Partial<TimelineElement>;
|
buildBaseUpdates: ({ value }: { value: number }) => Partial<TimelineElement>;
|
||||||
|
buildAdditionalKeyframes?: ({
|
||||||
|
value,
|
||||||
|
}: { value: number }) => Array<{ propertyPath: AnimationPropertyPath; value: number }>;
|
||||||
}) {
|
}) {
|
||||||
const editor = useEditor();
|
const editor = useEditor();
|
||||||
const snapValue = (value: number) =>
|
const snapValue = (value: number) =>
|
||||||
|
|
@ -50,19 +54,26 @@ export function useKeyframedNumberProperty({
|
||||||
const previewValue = ({ value }: { value: number }) => {
|
const previewValue = ({ value }: { value: number }) => {
|
||||||
const nextValue = snapValue(value);
|
const nextValue = snapValue(value);
|
||||||
if (shouldUseAnimatedChannel) {
|
if (shouldUseAnimatedChannel) {
|
||||||
|
const additionalKeyframes = buildAdditionalKeyframes?.({ value: nextValue }) ?? [];
|
||||||
|
const updatedAnimations = [
|
||||||
|
{ propertyPath, value: nextValue },
|
||||||
|
...additionalKeyframes,
|
||||||
|
].reduce(
|
||||||
|
(currentAnimations, keyframe) =>
|
||||||
|
upsertElementKeyframe({
|
||||||
|
animations: currentAnimations,
|
||||||
|
propertyPath: keyframe.propertyPath,
|
||||||
|
time: localTime,
|
||||||
|
value: keyframe.value,
|
||||||
|
}),
|
||||||
|
animations,
|
||||||
|
);
|
||||||
editor.timeline.previewElements({
|
editor.timeline.previewElements({
|
||||||
updates: [
|
updates: [
|
||||||
{
|
{
|
||||||
trackId,
|
trackId,
|
||||||
elementId,
|
elementId,
|
||||||
updates: {
|
updates: { animations: updatedAnimations },
|
||||||
animations: upsertElementKeyframe({
|
|
||||||
animations,
|
|
||||||
propertyPath,
|
|
||||||
time: localTime,
|
|
||||||
value: nextValue,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
@ -125,15 +136,17 @@ export function useKeyframedNumberProperty({
|
||||||
const commitValue = ({ value }: { value: number }) => {
|
const commitValue = ({ value }: { value: number }) => {
|
||||||
const nextValue = snapValue(value);
|
const nextValue = snapValue(value);
|
||||||
if (shouldUseAnimatedChannel) {
|
if (shouldUseAnimatedChannel) {
|
||||||
|
const additionalKeyframes = buildAdditionalKeyframes?.({ value: nextValue }) ?? [];
|
||||||
editor.timeline.upsertKeyframes({
|
editor.timeline.upsertKeyframes({
|
||||||
keyframes: [
|
keyframes: [
|
||||||
{
|
{ trackId, elementId, propertyPath, time: localTime, value: nextValue },
|
||||||
|
...additionalKeyframes.map((keyframe) => ({
|
||||||
trackId,
|
trackId,
|
||||||
elementId,
|
elementId,
|
||||||
propertyPath,
|
propertyPath: keyframe.propertyPath,
|
||||||
time: localTime,
|
time: localTime,
|
||||||
value: nextValue,
|
value: keyframe.value,
|
||||||
},
|
})),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,9 @@ export function TransformTab({
|
||||||
...(isScaleLocked ? { scaleY: value } : {}),
|
...(isScaleLocked ? { scaleY: value } : {}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
buildAdditionalKeyframes: isScaleLocked
|
||||||
|
? ({ value }) => [{ propertyPath: "transform.scaleY", value }]
|
||||||
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const scaleY = useKeyframedNumberProperty({
|
const scaleY = useKeyframedNumberProperty({
|
||||||
|
|
@ -140,6 +143,9 @@ export function TransformTab({
|
||||||
...(isScaleLocked ? { scaleX: value } : {}),
|
...(isScaleLocked ? { scaleX: value } : {}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
buildAdditionalKeyframes: isScaleLocked
|
||||||
|
? ({ value }) => [{ propertyPath: "transform.scaleX", value }]
|
||||||
|
: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const scaleFieldPropsX = {
|
const scaleFieldPropsX = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue