Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animate drag and drop using FLIP approach and simplify calculation of all elements #264

Merged
merged 8 commits into from
Sep 27, 2024

Conversation

cibernox
Copy link
Collaborator

@cibernox cibernox commented Sep 27, 2024

This PR overhauls how the elements calculate its positions and animate on the screen.

Before this change, elements didn't really change order until the mouse was lifted and the dragged element dropped. Instead, the right transform was applied to all elements as the mouse moved.

However this approach was complicated because it forced us to calculate where the elements would be positioned if the dragged element was to be dropped, which is easy in some cases but super complicated in others (e.g. if the elements are inline-block and they wrap to a second line, our calculations would have to be as complicated as the ones the browser does to know where to put elements).
This was not a sensible approach for the most complex layouts.

After this change, we use the F.L.I.P approach to animations (First, Last, Invert, Play).
That is, we store the elements position before, then elements are reordered for real as the mouse moves, so the browser does the calculation for us and places them on their last position. Then, we applied a transform to make them seem like they are where they were at the beginning and finally we play an animations that returns them to their real and final positions.

This approach is valid for any layout, as it's the browser the one doing the hard math, therefore it will enable X/Y dragging with little effort.

Screen.Recording.2024-09-27.at.18.33.41.mov

@cibernox cibernox self-assigned this Sep 27, 2024
@cibernox cibernox requested a review from leandrocp September 27, 2024 17:14
@cibernox cibernox merged commit 5ca3fc0 into main Sep 27, 2024
leandrocp pushed a commit that referenced this pull request Oct 9, 2024
… all elements (#264)

* Starts to work

* Seems to work even better, while using less code

* Save progress

* Use flip animation

* auto format code

* Simplify methods so they don't need drag direction

* auto format code

---------

Co-authored-by: cibernox <cibernox@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants