Integrating View Transitions API with Phoenix LiveView

317
clicks
Integrating View Transitions API with Phoenix LiveView

Source: readyforproduction.dev

Type: Post

Marcelo highlights the challenges of animating transitions between different DOM states and introduces the View Transitions API as an experimental tool designed to simplify this process. This API captures snapshots of the old and new states of the DOM during updates, allowing developers to animate transitions using a tree of pseudo-elements. To activate this feature, developers can wrap DOM modifications using `document.startViewTransition()`. The API currently supports JavaScript-based updates, with plans to support multi-page applications in the future. Marcelo's post also documents an experiment where he hacks the Phoenix LiveView `applyDiff` method from view.js to incorporate this API, describing the approach taken for this experiment. He provides instructions on how to try out the integration, using either a custom build process for a fork or modifying the `priv/static/assets/app.js` after running the Phoenix server. Through a Thermostat Example from the official LiveView documentation, Marcelo demonstrates the effect of API implementation and notes the potential for creating complex animations. He concludes with the status of the View Transitions API's browser support and candidate recommendation status, expressing hope for its rapid advancement.

© HashMerge 2024