-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates to: #3516 When integrating external animation libraries like motion.dev, the existing JS functions are not sufficient. Instead, the third party library needs to be triggered via JS. This has the downside of not being able to block the DOM until the animation is complete, which prevents this from working when elements are removed using `phx-remove`. This commit introduces a new `blocking: true` option to `JS.dispatch/3`, which injects a `done` function into the event's `detail` object. Using this with motion could look like this: ```elixir def render(assigns) do ~H""" <div :if={@show} phx-remove={JS.dispatch("motion:rotate", blocking: true)}> ... </div> """ end ``` ```javascript const { animate } = Motion window.addEventListener("motion:rotate", (e) => { animate(e.target, { rotate: [0, 360] }, { duration: 1 }).then(() => { if (e.detail.done) { e.detail.done() } }) }) ``` It is still necessary to block the DOM while the remove animation is running, as the remove can happen because of a navigation, where the animation would otherwise not run as the whole LiveView is just replaced.
- Loading branch information
Showing
3 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters