nuclearpasta / react-native-drax

A drag-and-drop system for React Native
MIT License
554 stars 69 forks source link

animate drop end similarly to snapback #159

Closed gdanov closed 1 year ago

gdanov commented 1 year ago

in issue https://github.com/nuclearpasta/react-native-drax/issues/28 custom animation can be provided for snap back. I'd like to have custom animation on drop (have the item disappear via animating transform 1 -> 0 for example). Is that currently possible?

lafiosca commented 1 year ago

It's not well-documented, and I am not certain from my current recollections. I would start by looking here:

https://github.com/nuclearpasta/react-native-drax/blob/dbedea923ff87860da1b3112f06387fe879ad091/src/types.ts#L206-L210

I think you should be able to use the drop lifecycle event handlers in combination with a snapbackAnimator to get custom drop animation behavior (perhaps by setting some kind of state if necessary), and optionally they can return custom snapback targets. By default, I think the snapback target for a successful drop is the receiver of the drop. The snapbackAnimator should be honored regardless of whether snapping back to the original position, the receiver position, or a custom target.

lafiosca commented 1 year ago

That is to say: "snapback" is perhaps a misleading name, because it can actually snap "forward" too.

gdanov commented 1 year ago

Do I understand correctly that when the draggable is over valid target, the snapping will happen towards the target?

If that's the case, I get it, will experiment. Thanks a lot!

gdanov commented 1 year ago

It worked! Pretty neat design :)

lafiosca commented 1 year ago

Yes that's correct, glad it worked for you :)