Announcing Elm Animator

Elm Animator is now out! :tada:

This has been a long time coming and I’m excited to finally put it out into the world. I’ll be hanging out in the #animations channel on the Elm slack in case anyone has any questions!

Here’s the original talk I gave at Elm Europe, The Immutable Animator’s Toolkit.

TLDR - This library takes an approach of turning a value into a Timeline value where you can animate between the states. This means you’re animating based on state you’re already tracking. If you want, the library can dynamically generate CSS keyframes for you for some easy performance!

So, an example of animating a timeline of Bool for a checkbox, is roughly the following:

-- in your model 
	{ checked : Animator.Timeline Bool }

-- in your view:
    div
        [ Animator.Inline.opacity model.checked <|
            \checked ->
                if checked then
                   Animator.at 1

                else
                   Animator.at 0
        ]
        [ text “👍” ]

The Goal of a Continuous UI

Animation can either be a nuanced, playful helper in your UI, or it can be a nuisance.

There’s an immediate question of what kinds of animation we want to cultivate in the Elm community.

With that in mind, here are two types of animation that I’d love to emphasize and elm-animator should be very useful for both.

Continuous UI

A continuous UI minimizes context-shifting for a user and allows them to build a spatial model of your interface.

We’re generally used to pieces of UI popping in and out of existence, and pages that change drastically on click. Everytime something changes, it’s a context shift for your user.

We can use animation to make that experience continuous so our users can build a quick intuition about how our interfaces work.

Sarah Drasner has an excellent talk showing what a continuous UI interaction can look like.

There’s also a fairly basic page transition example - (Code) for this library that has the same principle.

Calm Enrichment

The second type is something I think of as calm enrichment.

The floating city on the Elm Japan Website (you’ll need to scroll down a little) is wonderful!

It doesn’t distract from what I’m trying to accomplish on the website, it simply sits there, calmly floating. It doesn’t take anything away from my budget of attention that I have when visiting the website. In fact it likely increases the amount of attention I’m willing to pay.

They used elm-playground (which I am likewise inspired by) to achieve the effect and convinced me to make this sort of thing easy in elm-animator.

The Successor to Elm Style Animation

Elm Style Animation had a scaling problem. :confused:

What does that mean? Well, every animated element needed a Animation.State in your model.

This meant for more complex animations(~10 elements? is that even that complex?), there was a lot of boilerplate necessary to get things going.

elm-animator doesn’t have this problem. You could animate n elements for any given timeline. And the timeline is likely based on state you’re already storing in your model!

That, combined with the fact that elm-animator can generate CSS keyframes means I consider elm-animator to be elm-style-animation’s successor.

Next step, Elm UI

This release is about creating a solid animation engine for anyone to use, though my ultimate goal is to bring a nice story around animation directly to elm-ui.

So it’s likely that the next release of elm-ui will depend on this library directly.

Inspiration

I was inspired by these talks! Liz and Andrew both built some really cool stuff in Elm. My goal was to build something that would help them in their future endeavors.

86 Likes

Congrats on the release!!! :heart_eyes_cat:

5 Likes

Aw thanks Matt! Looking forward to trying this out

3 Likes

Looks sweet!

elm-animator can generate CSS keyframes

Could you elaborate a bit on that? Does that mean it can work without generating messages on every tick? One problem I have with JS ticks is not even the performance, but the fact that they flood the Elm debugger, making it next to impossible to debug the actual app state. Maybe it wouldn’t be a problem if Elm debugger had filtering.

Mind that I’m a noob though, so I might be missing something.

my ultimate goal is to bring a nice story around animation directly to elm-ui

That’d be great (probably). I’ve yet to try elm-ui, but it looks very appealing :slight_smile:

1 Like

You basically got it :smiley:

When using Animator.Css, essentially there will be only one Tick, then this library will generate all CSS @keyframes it needs to animate the current series of transitions/resting animations.

If the timeline changes state at all (If you’re animating booleans, lets say you tell it to Animator.go quickly False), then you’d get another single frame where the @keyframes would be generated.

This also works when interrupting a current animation. Since the library knows the position and momentum of the animated value, it can smoothly redirect everything to a new target.

7 Likes

Awesome! Thanks a lot for clarifications, and, of course, for your work!

1 Like

The README now has compiled examples so people can play with them without having to clone and compile stuff.

2 Likes

Been looking forward to this one! Thank you so much :sunny:

1 Like

I love elm-style-animation and can’t wait to try elm animator! Thanks for the all your amazing librairies!!

1 Like

I absolutely LOVE the API design! Great work, Matt! :heart:

1 Like

I should also mention some packages that were invaluable in developing this package!

:raised_hands: - Thank you Ian and Tereza

  • Elm Geometry helped me figure out some vector math that I was not familiar with.
  • Elm Units, when you’re drowning in time values, having a type distinction between absolute times and durations is a lifesaver.
  • Line Charts - In order to gain visibility into how the values were being interpolated I made a lot of line charts. Tereza’s package was really nice to work with.
13 Likes

The package looks great and I took the time to listen to your talk which was also really interesting.

Will we be able to use CSS animations on SVG with this package? To me it looks like I would be able to manually turn the output of Animator.xy into an Svg.Attribute msg, but there seems to be no way to do this for Animator.Css or Animator.Inline.

Is css animation of svg out of scope for this package or am I missing something?

1 Like

Excited to see the integration with elm-ui! :star_struck:

2 Likes

SVG is a large beast, so it was intentionally left out for the 1.0 release. But I’m definitely interested in exploring!

The intention was for people to use something like Animator.xy in those cases for now. Just because they don’t render to css keyframes doesn’t mean they’re not performant or useful!

I mention SVG on the roadmap. Basically there’s a question of ‘is there an advantage to rendering to something like SMIL?’

1 Like

Congrats on the release! Can’t wait to try it out.

1 Like

This is fantastic. I have always thought elm has no good answer to animations but this is just wonderful.

1 Like

Couldn’t sleep last night, so decided to have a play with this on a current project.

Didn’t take long at all to get an image fading in as the app starts - that’s not trying to say “I’m great”, but that this package and API is the best thing to hit Elm since Elm-UI - for me anyway. Slept soundly after achieving that :sleeping: :sleeping: :slight_smile:

Continued with it today, and now have a few animations running one after the other using Animator.queue.

Thanks for this @mdgriffith, for me, it’s going to be an automatic install on new projects now, just like Elm-UI, especially after reading the section titled ‘Continuous UI’ and watching Sarah Drasner’s talk you linked to in the README - very informative.

Thanks and cheers :beers:

4 Likes

Good job! It’s especially awesome to see such clear examples :+1:

As a big fan of Elm-UI I look forward to the potential tighter integration between the two. Although, already now animating an existing ui was straightforward. I wrote a simple test on Ellie using Elm-UI and then added some animation to it: https://ellie-app.com/8DhYXm2hDXQa1 Fun! :slightly_smiling_face:

My test case was sorting a “table”. Animating the table was easy but how about animating each row separately so that the effect would actually look like sorting? Looks like I should have a Timeline per table row and then use the Animator to update all timelines when the rows sort to a new order… :thinking:

2 Likes

Amazing :slight_smile: And very inspiring !

1 Like

Do you have any examples of this handy? It’d be cool to see how we could do it in our own apps as a dev tool to compare and play with different animations. Thanks!

Also, congrats on the release! Been excited for this since your talk.

1 Like