From afbf0cb01edf09f4169fbef7878412e619b1d078 Mon Sep 17 00:00:00 2001 From: Jan Dockal Date: Wed, 16 Oct 2019 11:58:28 +1300 Subject: [PATCH] feat(DraggableCore): apply scale property while dragging an element --- lib/DraggableCore.js | 7 ++++ lib/utils/domFns.js | 6 ++-- lib/utils/positionFns.js | 2 +- specs/draggable.spec.jsx | 76 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/lib/DraggableCore.js b/lib/DraggableCore.js index 4fbabfd2..2429a612 100644 --- a/lib/DraggableCore.js +++ b/lib/DraggableCore.js @@ -67,6 +67,7 @@ export type DraggableCoreProps = { onDrag: DraggableEventHandler, onStop: DraggableEventHandler, onMouseDown: (e: MouseEvent) => void, + scale: number, }; // @@ -185,6 +186,11 @@ export default class DraggableCore extends React.Component's events diff --git a/specs/draggable.spec.jsx b/specs/draggable.spec.jsx index 83725154..9946ad27 100644 --- a/specs/draggable.spec.jsx +++ b/specs/draggable.spec.jsx @@ -683,6 +683,44 @@ describe('react-draggable', function () { simulateMovementFromTo(drag, 200, 200, 300, 300); }); + + it('should call back with correct position when parent element is 2x scaled', function() { + function onDrag(event, data) { + // visually it will look like 100, because parent is 2x scaled + assert(data.x === 50); + assert(data.y === 50); + assert(data.deltaX === 50); + assert(data.deltaY === 50); + assert(data.node === ReactDOM.findDOMNode(drag)); + } + drag = TestUtils.renderIntoDocument( + +
+ + ); + + // (element, fromX, fromY, toX, toY) + simulateMovementFromTo(drag, 0, 0, 100, 100); + }); + + it('should call back with correct position when parent element is 0.5x scaled', function() { + function onDrag(event, data) { + // visually it will look like 100, because parent is 0.5x scaled + assert(data.x === 200); + assert(data.y === 200); + assert(data.deltaX === 200); + assert(data.deltaY === 200); + assert(data.node === ReactDOM.findDOMNode(drag)); + } + drag = TestUtils.renderIntoDocument( + +
+ + ); + + // (element, fromX, fromY, toX, toY) + simulateMovementFromTo(drag, 0, 0, 100, 100); + }); }); describe('DraggableCore callbacks', function () { @@ -703,6 +741,44 @@ describe('react-draggable', function () { // (element, fromX, fromY, toX, toY) simulateMovementFromTo(drag, 0, 0, 100, 100); }); + + it('should call back with correct position when parent element is 2x scaled', function() { + function onDrag(event, data) { + // visually it will look like 100, because parent is 2x scaled + assert(data.x === 50); + assert(data.y === 50); + assert(data.deltaX === 50); + assert(data.deltaY === 50); + assert(data.node === ReactDOM.findDOMNode(drag)); + } + drag = TestUtils.renderIntoDocument( + +
+ + ); + + // (element, fromX, fromY, toX, toY) + simulateMovementFromTo(drag, 0, 0, 100, 100); + }); + + it('should call back with correct position when parent element is 0.5x scaled', function() { + function onDrag(event, data) { + // visually it will look like 100, because parent is 0.5x scaled + assert(data.x === 200); + assert(data.y === 200); + assert(data.deltaX === 200); + assert(data.deltaY === 200); + assert(data.node === ReactDOM.findDOMNode(drag)); + } + drag = TestUtils.renderIntoDocument( + +
+ + ); + + // (element, fromX, fromY, toX, toY) + simulateMovementFromTo(drag, 0, 0, 100, 100); + }); });