I have successfully implemented a list of elements that can be dragged and dropped using Angular Material's drag and drop feature, similar to the tutorial available at this link.
In my implementation, I have a "drop(event)" function that not only moves elements in the Angular model but also sends a request to the server and updates the model when a response is received. However, an issue arises where there is a noticeable jumping of elements because the Angular model is not changed immediately when dropping an element – it jumps back to its original position before moving to the new position once the server response is processed.
To make this process smoother for users, I want to somehow conceal the background work happening during the update.
- One solution could be to maintain two separate lists – one for the user interface and another for the server – and update them accordingly (the user list upon drop and the server list upon response), but this approach may be difficult to manage.
I am exploring the idea of using CSS animations to address the issue. The drag and drop example already demonstrates the use of:
.cdk-drag-animating {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
The 'transition: transform' property provides a smooth animation when an element is dropped. My aim is to show users a 0.5-second animation, which should provide ample time for the server response to update the model before the animation completes.
However, I noticed that the 'drop($event)' function is called after the transition ends, regardless of the duration set for the transition. This behavior seems unexpected to me as I assumed the function would be triggered upon releasing the mouse. Any insights on how to handle hiding the model update and resolving the issue with the CSS animation transitions?
Update: I have created an example showcasing the problem mentioned above. Click here to view the example.