React-beautiful-dnd: Create addon for physics based dragging item

Created on 6 Aug 2018  路  11Comments  路  Source: atlassian/react-beautiful-dnd

We could implement a similar dragging system to the blog: How to fix dragging animation in UI with simple math by Nash Vail.

We could implement this as a seperate npm package for consumers to opt in. Unlike the blog which is based on mouse position we could patch the DraggingStyle > transform directly. The x,y values can be pulled out of that, and the transform can be monkey patched.
I am thinking it should be a seperate package as it makes it clear how users could consume it without making it an option. If we are happy with the experience generally we could look at pulling it into the core library

I am thinking something like this:

import {patchTransform} from '....';

class Item extends React.Component {
    render() {
        return (
            <Draggable draggableId="draggable" index={0}>
                (provided, snapshot) => (
                 <div 
                    {...provided.draggableProps} 
                    {...provided.dragHandleProps}
                    ref={provided.innerRef}
                    style={patchTransform(snapshot.isDragging, provided.draggableProps.style)
                 >
                    Drag me!
                </div>
            </Draggable>
        )
    }
}
const patchTransform = (isDragging, style) => {
  if(!isDragging) {
    return style;
  }
  if(!style.transform) {
    return style;
  }

  // pull out the x,y values from the transform
  // apply an additional rotate transform
  return patched;
}

docs 馃摉 help wanted 馃憢 improvement 猸愶笍

Most helpful comment

All 11 comments

It probably should be a stateful component, so:

<Draggable draggableId="draggable" index={0}>
   {(provided, snapshot) => (
          <FancyDragAnimationOnSprings style={provided.draggableProps.style}>
              { style => 
        <div 
          {...provided.draggableProps} 
          {...provided.dragHandleProps}
          ref={provided.innerRef}
                  style={style}
                >
          Drag me!
        </div>
               }
       </FancyDragAnimationOnSprings>
   )}
</Draggable>

I don't really mind what pattern of reuse it uses. Mine was just a suggestion

To avoid multiple people working on this - if you are interested it working on this just say so here 馃憤

working on it

Brilliant!!!

We should add a section to the docs to let people know that this exists! An add-on section?

We now need to add a section to the docs 馃憤

I'll create PR

Thanks @rokborf!! #841

Was this page helpful?
0 / 5 - 0 ratings

Related issues

screenmeet picture screenmeet  路  3Comments

OmriAharon picture OmriAharon  路  3Comments

heymartinadams picture heymartinadams  路  3Comments

alexreardon picture alexreardon  路  3Comments

FutureKode picture FutureKode  路  3Comments