Skip to content

Commit

Permalink
Exposing isDropAnimating in Draggable Snapshot (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
balnagy authored and alexreardon committed Jul 3, 2018
1 parent 1c390c9 commit c336e45
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,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 @@ -1349,6 +1354,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 @@ -301,6 +301,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

0 comments on commit c336e45

Please sign in to comment.