Skip to content

Commit

Permalink
Fixed incorrect starting keyframe for sortable animation
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Sep 19, 2024
1 parent 3942270 commit 41ee331
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
12 changes: 7 additions & 5 deletions packages/dom/src/sortable/sortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import type {
} from '@dnd-kit/dom';
import {
animateTransform,
getComputedStyles,
computeTranslate,
scheduler,
ProxiedElements,
} from '@dnd-kit/dom/utilities';

Expand Down Expand Up @@ -191,7 +191,7 @@ export class Sortable<T extends Data = Data> {
return;
}

scheduler.schedule(() => {
manager.renderer.rendering.then(() => {
const {element} = this;

if (!element) {
Expand All @@ -209,15 +209,17 @@ export class Sortable<T extends Data = Data> {
y: shape.boundingRectangle.top - updatedShape.boundingRectangle.top,
};

const {x, y, z} = computeTranslate(element);
const {translate} = getComputedStyles(element);
const currentTranslate = computeTranslate(element, translate, false);
const finalTranslate = computeTranslate(element, translate);

if (delta.x || delta.y) {
animateTransform({
element,
keyframes: {
translate: [
`${x + delta.x}px ${y + delta.y}px ${z}`,
`${x}px ${y}px ${z}`,
`${currentTranslate.x + delta.x}px ${currentTranslate.y + delta.y}px ${currentTranslate.z}`,
`${finalTranslate.x}px ${finalTranslate.y}px ${finalTranslate.z}`,
],
},
options: transition,
Expand Down
1 change: 0 additions & 1 deletion packages/dom/src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ export {
inverseTransform,
parseTransform,
parseTranslate,
stringifyTransform,
} from './transform/index.ts';
export type {Transform} from './transform/index.ts';
30 changes: 17 additions & 13 deletions packages/dom/src/utilities/transform/computeTranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,34 @@ function getFinalKeyframe(
return null;
}

export function computeTranslate(element: Element): {
export function computeTranslate(
element: Element,
translate = getComputedStyles(element).translate,
projected = true
): {
x: number;
y: number;
z: number;
} {
const keyframe = getFinalKeyframe(
element,
(keyframe) => 'translate' in keyframe
);
if (projected) {
const keyframe = getFinalKeyframe(
element,
(keyframe) => 'translate' in keyframe
);

if (keyframe) {
const {translate = ''} = keyframe;
if (keyframe) {
const {translate = ''} = keyframe;

if (typeof translate === 'string') {
const finalTranslate = parseTranslate(translate);
if (typeof translate === 'string') {
const finalTranslate = parseTranslate(translate);

if (finalTranslate) {
return finalTranslate;
if (finalTranslate) {
return finalTranslate;
}
}
}
}

const {translate} = getComputedStyles(element);

if (translate) {
const finalTranslate = parseTranslate(translate);

Expand Down
1 change: 0 additions & 1 deletion packages/dom/src/utilities/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export {inverseTransform} from './inverseTransform.ts';
export {parseTransform} from './parseTransform.ts';
export {parseTranslate} from './parseTranslate.ts';
export type {Transform} from './parseTransform.ts';
export {stringifyTransform} from './stringifyTransform.ts';
5 changes: 0 additions & 5 deletions packages/dom/src/utilities/transform/stringifyTransform.ts

This file was deleted.

0 comments on commit 41ee331

Please sign in to comment.