atlassian / react-beautiful-dnd

Beautiful and accessible drag and drop for lists with React
https://react-beautiful-dnd.netlify.app
Other
33.37k stars 2.57k forks source link

Animation canceled when dropped programmatically #1901

Open jvmanke opened 4 years ago

jvmanke commented 4 years ago

Hello, I am trying to programmatically apply changes coming from my backend to a dnd controlled list.

Letting the data update freely causes my cards to instantly switch places (expected), however I would like the animations of cards changing places to happen.

What I thought of doing was to write a sensor that, before applying the changes to my droppable array, move each to the right place. I used the story as an example, but realized that when in succession doing, for example, actions.moveRight(); actions.drop();, the droppable is translated instantly to the new place instead of animating.

Expected behavior

Droppable animates to the position, and then is dropped.

Actual behavior

Droppable is moved and dropped instantly.

Steps to reproduce

Add the following sensor to a DragDropContext and call moveDown(someId) in the console:

const consoleSensor = (api) => {
  window.api = api;
  window.moveDown = (id) => {
    const pdActions = api.tryGetLock(id);
    const actions = pdActions.snapLift();

    actions.moveDown();
    actions.drop();
  };
};

What version of React are you using?

16.13.1

What version of react-beautiful-dnd are you running?

13.0.0

What browser are you using?

Google Chrome - Version 84.0.4147.105 (Official Build) (64-bit)

Demo

Run moveDown("item-1") on the sandbox console, moveDownDelay("item-1") shows that the animation happens, but is canceled by the drop frunction:

https://codesandbox.io/s/vertical-list-3wx8r

enamodeka commented 3 years ago

@jvmanke As far as I know this is not part of the package.

There's an article on how to achieve it with fluid dragging: https://dev.to/raathigesh/scripted-natural-motion-with-react-beautiful-dnd-4ifj

MonkeyPanic commented 3 years ago

Same here. The animation is canceled when drop() is used. But if I omit drop() the animation is being executed (but lock is not released). fluid dragging with tweens like in the article works.

wmonecke commented 3 years ago

@jvmanke @MonkeyPanic Have any of you guys made it work? I am on the same boat and I am hitting a wall.