benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype which allows you to control animations directly from the server.
The key difference is, that the actual animations will happen in a very performant way directly on the client. So there is nothing like “send every animation frame over the wire happening”.
What do you think about that? I’m thinking to turn this into a library.
Here a little demo video: https://cleanshot-cloud-fra.accelerator.net/media/26144/JoVUJgqmm21U6URHXo5RBP8haH0NZOZQayGHEMYL.mp4
Trending in RFCs
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
bdarla
The link above looks suspicious… I wouldn’t click.
Update, indeed, the link has been updated and it is safe to watch.
benlime
Sorry, I could not find a way to embed a video here. I updated the link with a “direct” Link to the video. The link contains an online player.
Edit: Seems like it automatically detects video link. Should work now.
thomasbrus
That’s pretty neat! I wonder how
<.motion />is implemented?Quite nice how you can abstract away things such as animations using Phoenix function components. It reminds me of React.
I assume every animation frame is sent over the wire via LiveView (using slightly differentstyleattribute).Oh, and this is quite a stretch perhaps, but if you turn this into a library it would be nice to have an option to enable client-side animation. Cause I can imagine if a user is on a less stable connection (on mobile for example) the animation may not be so smooth.^ Oh I misread, the animations do happen client side?
benlime
Exactly, the animations fully happen on the client. The only thing which is sent over the wire are the animation props
animateandtransition. There is also a propinitialwhich allows you to set an initial state (think of enter animations where you need the state to be something else on initial mount).This also works flawlessly when re-triggering animations. When you hammer the button in the video, it will just animate in the other direction from the exact point when you clicked at it. You can even do complex animations with multiple steps by just providing e.g.
animate={[x: [0, 200, 100, 50, 100]}.The function component itself currently is extremely simple. I’ll just paste it.
There is a
phx-hookinvolved which utilities a tiny JS library (motion.dev) that performs animations using the browser WebAnimations API.I took heavy inspiration in the API from
framer-motion(Motion: JavaScript & React animation library). I really like their api design and the paradigm for declaring animations. Still, I have to implement a few features and figure out things, like:LiveView.JS.A lot of ideas, but I think in general most of it is somewhat possible.
benlime
I’m pretty amazed what you can do with LiveView. I just played around with declaring fully client-side interactions using a thin wrapper around
LiveView.JS.Toggle animations declared on the server, performed on the client without a round-trip. And you can even mix and match animations being updated from the server and the animations already running locally
.
When clicking the square, the server updates the LiveView state, therefore updating the animation (again, it just sends one single declaration, nothing more).
When clicking the “Toggle me” button, no round-trip is made.
Hammering both just smoothly animates. Feels magical to me.
https://cleanshot-cloud-fra.accelerator.net/media/26144/p5RbCZhU7yRjtyBAb6E9U0LCNjzeJgBvGjP4Tqc7.mp4
cspags
Wow, this is seriously awesome!! Would love to experiment with it if you end up releasing it as a library.
03juan
Fantastic addition to the live view paradigm. I feel at this point you have no choice but to release it as a library, to be honest.
With the upcoming changes in master this will be even more powerful
AstonJ
What @03juan said^^
benlime
Thanks for the feedback. I appreciate it very much. So as I have quite a lot of fun building this anyway, I’ll release this as a library. It’s still missing a few features and tests - and docs of course.
I’ll have more time to work on it in a week, so I expect a first releasable version in two weeks or so. I’m pretty excited what else can be achieved here.
kingdomcoder
Funny how I spent this week thinking about animations in LiveView
Animations seemed to be the only missing convenience that’d make Elixir Desktop a competitive mobile framework.
Now it seems that’s being solved.
Kudos @benlime