react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

Adding the option for percentag based dragging

Open AndrewRayCode opened this issue 10 years ago • 3 comments
trafficstars

This is an initial attempt at adding percentage based offsets to address #63.

One of the odd things in this plugin is the ability to cancel the drag events by returning false from onDrag. I don't think this is healthy for the API. This change initially ignore the return value in the the drag callback for code convenience.

If this works for you I can clean up the code a bit, make sure it matches style, and update the documentation.

AndrewRayCode avatar Jun 14 '15 01:06 AndrewRayCode

Coincidentally was after this functionality myself this evening and stumbled across your PR! :smile:

Have tested this locally, seems to work ok with a few issues (that you're possibly already aware of):

  • You'll probably want to initialize percentX and percentY in getInitialState to preserve the start= method's functionality in percent mode:
--- a/lib/draggable.js
@@ -515,7 +514,8 @@ module.exports = React.createClass({
       offsetX: 0, offsetY: 0,

       // Current transform x and y.
-      clientX: props.start.x, clientY: props.start.y
+      clientX: props.start.x, clientY: props.start.y,
+      percentX: props.start.x, percentY: props.start.y
     };
   },
  • The element's offset to the dragpoint isn't being correctly determined in your positioning calculation, so when you click to drag an element, it snaps the elements top left corner (0,0) to match your cursor, like so:

drag-snap

Had a bash at trying to fix that but couldn't wrap my head around the right numbers and ran out of time.

supermario avatar Jun 14 '15 11:06 supermario

I like this idea, but it will be much easier to implement on top of <DraggableCore>. Expect the refactor to hit in the next few days.

https://github.com/mzabriskie/react-draggable/tree/coreRefactor

STRML avatar Jun 23 '15 22:06 STRML

This is a TODO for me now that v1.0.0 is out.

STRML avatar Oct 27 '15 21:10 STRML