Skip to content

Commit

Permalink
fix: Transformations not applied on state change
Browse files Browse the repository at this point in the history
* Check if transform fix is enabled before applying position
  • Loading branch information
bcakmakoglu committed Aug 17, 2021
1 parent ed95a0a commit d9d664a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useDraggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const useDraggable = (target: MaybeRef<any>, options: Partial<DraggableOptions>)
});

const transform = () => {
if (!get(node) || get(state).update === false || !get(state).dragging) return;
if (!get(node) || get(state).update === false) return;
if (get(state).enableTransformFix) removeTransformFix();

const offset = get(state).positionOffset;
Expand Down Expand Up @@ -263,7 +263,11 @@ const useDraggable = (target: MaybeRef<any>, options: Partial<DraggableOptions>)
get(state).y = pos.y;
get(state).prevPropsPosition = { ...pos };
}
transform();
if (get(state).enableTransformFix) {
applyTransformFix();
} else {
transform();
}
};

tryOnUnmounted(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export interface DraggableOptions extends DraggableCoreOptions {
defaultPosition: ControlPosition;
positionOffset?: PositionOffsetControlPosition;
position?: ControlPosition;
x: number;
y: number;
}

export interface DraggableCoreOptions {
Expand All @@ -63,7 +61,8 @@ export interface DraggableCoreOptions {

export type DraggableCoreState = State & DraggableCoreOptions;

export type DraggableState = State & DraggableOptions & { prevPropsPosition: { x: number; y: number }; isElementSVG: boolean };
export type DraggableState = State &
DraggableOptions & { x: number; y: number; prevPropsPosition: { x: number; y: number }; isElementSVG: boolean };

interface State {
dragging: boolean;
Expand Down

2 comments on commit d9d664a

@vercel
Copy link

@vercel vercel bot commented on d9d664a Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d9d664a Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.