From c336e4541045122c2ee2ad7388eae46f42a51e11 Mon Sep 17 00:00:00 2001 From: Balazs Nagy Date: Tue, 3 Jul 2018 08:22:59 +0200 Subject: [PATCH] Exposing isDropAnimating in Draggable Snapshot (#559) --- README.md | 6 ++++++ src/view/draggable/draggable-types.js | 1 + src/view/draggable/draggable.jsx | 1 + .../drag-drop-context/error-handling.spec.js | 2 ++ test/unit/view/unconnected-draggable.spec.js | 17 +++++++++++++++++ 5 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 21f8efa1fb..bc73372138 100644 --- a/README.md +++ b/README.md @@ -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, |}; @@ -1349,6 +1354,7 @@ type DraggableProvided = {| type DraggableStateSnapshot = {| isDragging: boolean, + isDropAnimating: boolean, draggingOver: ?DroppableId, |}; diff --git a/src/view/draggable/draggable-types.js b/src/view/draggable/draggable-types.js index 8652deb7a0..ba3a059588 100644 --- a/src/view/draggable/draggable-types.js +++ b/src/view/draggable/draggable-types.js @@ -72,6 +72,7 @@ export type Provided = {| export type StateSnapshot = {| isDragging: boolean, + isDropAnimating: boolean, draggingOver: ?DroppableId, |}; diff --git a/src/view/draggable/draggable.jsx b/src/view/draggable/draggable.jsx index c357ff054b..81472a2c10 100644 --- a/src/view/draggable/draggable.jsx +++ b/src/view/draggable/draggable.jsx @@ -301,6 +301,7 @@ export default class Draggable extends Component { draggingOver: ?DroppableId, ): StateSnapshot => ({ isDragging: isDragging || isDropAnimating, + isDropAnimating: isDropAnimating, draggingOver, }), ); diff --git a/test/unit/view/drag-drop-context/error-handling.spec.js b/test/unit/view/drag-drop-context/error-handling.spec.js index 78215fc13e..5de487ea15 100644 --- a/test/unit/view/drag-drop-context/error-handling.spec.js +++ b/test/unit/view/drag-drop-context/error-handling.spec.js @@ -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); @@ -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); diff --git a/test/unit/view/unconnected-draggable.spec.js b/test/unit/view/unconnected-draggable.spec.js index f7b8314485..1de821d6a2 100644 --- a/test/unit/view/unconnected-draggable.spec.js +++ b/test/unit/view/unconnected-draggable.spec.js @@ -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', () => {