Skip to content
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

Exposing isDropAnimating in Draggable Snapshot #559

Merged
merged 4 commits into from
Jul 3, 2018
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,12 @@ const myOnMouseDown = event => console.log('mouse down on', event.target);

```js
type DraggableStateSnapshot = {|
// True, if Draggable is being dragged
isDragging: boolean,
// True, if Draggable is dropped and animated to its final position.
// Not always flipped to `true` when dropped, for example keyboard interaction or perfectly positioned drop
// does not initiate animation
isDropAnimating: boolean,
// What Droppable (if any) the Draggable is currently over
draggingOver: ?DroppableId,
|};
Expand Down Expand Up @@ -1351,6 +1356,7 @@ type DraggableProvided = {|

type DraggableStateSnapshot = {|
isDragging: boolean,
isDropAnimating: boolean,
draggingOver: ?DroppableId,
|}

Expand Down
1 change: 1 addition & 0 deletions src/view/draggable/draggable-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type Provided = {|

export type StateSnapshot = {|
isDragging: boolean,
isDropAnimating: boolean,
draggingOver: ?DroppableId,
|};

Expand Down
1 change: 1 addition & 0 deletions src/view/draggable/draggable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export default class Draggable extends Component<Props> {
draggingOver: ?DroppableId,
): StateSnapshot => ({
isDragging: isDragging || isDropAnimating,
isDropAnimating: isDropAnimating,
draggingOver,
}),
);
Expand Down
2 changes: 2 additions & 0 deletions test/unit/view/drag-drop-context/error-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ it('should reset the application state and swallow the exception if an invariant
const expected: DraggableStateSnapshot = {
draggingOver: null,
isDragging: false,
isDropAnimating: false,
};
// no longer dragging
expect(willThrough.props().snapshot).toEqual(expected);
Expand All @@ -123,6 +124,7 @@ it('should not reset the application state an exception occurs and throw it', ()
const expected: DraggableStateSnapshot = {
draggingOver: null,
isDragging: false,
isDropAnimating: false,
};
// no longer dragging
expect(willThrough.props().snapshot).toEqual(expected);
Expand Down
17 changes: 17 additions & 0 deletions test/unit/view/unconnected-draggable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,23 @@ describe('Draggable - unconnected', () => {
const snapshot: StateSnapshot = getLastCall(myMock)[0].snapshot;
expect(snapshot.draggingOver).toBe(null);
});

it('should let consumers know if drop animation is in progress', () => {
const mapProps: MapProps = {
...draggingMapProps,
isDropAnimating: true,
};

const myMock = jest.fn();

mountDraggable({
mapProps,
WrappedComponent: getStubber(myMock),
});

const snapshot: StateSnapshot = getLastCall(myMock)[0].snapshot;
expect(snapshot.isDropAnimating).toBe(true);
});
});

describe('drop animating', () => {
Expand Down