Skip to content

Drag behavior is correct after resetting data #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,13 @@ positionOffset: {x: number | string, y: number | string},
// Specifies the scale of the canvas your are dragging this element on. This allows
// you to, for example, get the correct drag deltas while you are zoomed in or out via
// a transform or matrix in the parent of this element.
scale: number
scale: number,

// Drag behavior is correct after resetting data
resetData: { x: number, y: number, slackX: number, slackY: number } | undefined,
}


```


Expand Down
8 changes: 7 additions & 1 deletion lib/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type DraggableProps = {
...DraggableDefaultProps,
positionOffset: PositionOffsetControlPosition,
position: ControlPosition,
resetData?: { x: number, y: number, slackX: number, slackY: number },
};

//
Expand Down Expand Up @@ -179,7 +180,7 @@ class Draggable extends React.Component<DraggableProps, DraggableState> {

// React 16.3+
// Arity (props, state)
static getDerivedStateFromProps({position}: DraggableProps, {prevPropsPosition}: DraggableState): ?Partial<DraggableState> {
static getDerivedStateFromProps({position,resetData}: DraggableProps, {prevPropsPosition}: DraggableState): ?Partial<DraggableState> {
// Set x/y if a new position is provided in props that is different than the previous.
if (
position &&
Expand All @@ -194,6 +195,11 @@ class Draggable extends React.Component<DraggableProps, DraggableState> {
prevPropsPosition: {...position}
};
}
if (resetData) {
return {
...resetData,
};
}
return null;
}

Expand Down