227

React UI animation made simple – jsdownunder – Medium

 6 years ago
source link: https://medium.com/jsdownunder/react-ui-animation-made-simple-c2ff98056659
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

React UI animation made simple

1*EB9th1YxD5mypXfQnU4UHw.png?q=20
react-ui-animation-made-simple-c2ff98056659

What makes UI elegant, sexy and beautiful? Design is the first thing that pops up in mind. The modern web has a long way to go! It’s time to push web UI to the next level with animations. I lost count how many times I was amazed by iOS and Android’s beautiful animation, while most of my web apps remain static and “boring”. Static design is like a beautiful 👸 on a poster. It doesn’t move or interact with you! Animation makes static UI alive and vivid.

Rewind back to my experience, toggling (showing/hiding) an element is one of the most common tasks in UI, which I have done like below for a long time… (shamefully)

Component toggle UI

I slowly evolved from this to css to perform the toggling.

Css StyleComponent toggle UI with classname

While that works, I often lost track of what the actual style looks like when glancing quickly at the code. I kept feeling this is not the best approach to implement animation.

There should be a better and easier way to perform animations in react. So I wrote my own. I present to you react-simple-animate.

React simple animation

A declarative and simple way to perform animation in react. I can control the start of the animation and the styles to apply at the end of the animation. This is a good pattern in my opinion. Hooray!

React Simple Animate

React simple animate 🤘 is the way to go! Oh yes, it’s my 2c worth contributing to the community after years of using open source software (first time too). The goal is make UI animation as easy as possible for react

Here are two awesome examples of what I was able to achieve using react-simple-animate:

1*B3dpLJF_p33hpmdt3wWA9A.gif?q=20
react-ui-animation-made-simple-c2ff98056659
Navigation with react-simple-animate(note the frame rate is dropped due to animated gif)
1*Vs7FN0m-dF5PGIMo4hiASA.gif?q=20
react-ui-animation-made-simple-c2ff98056659
react-simple-animate animates the svg map

While react simple animation is great it has some pros and cons:

😍 Pros:

  • Simple animation from inline style A to style B
  • Declarative for component animation
  • Make animation toggle easy
  • Support animation sequences
  • It’s tiny size

😑 Cons:

  • Does not support sequenced animation
  • Vendor prefix for style is not support out of box
  • it’s made for simple animation 🤘

The best way to see how simple it is to try it yourself, which you can do with the demo.

1*NNkqjrKquI6O1swGLlcAFQ.png?q=20
react-ui-animation-made-simple-c2ff98056659
React simple animate demo (you can tap on the <> button to see the code 😛)

Overall, I hope react-simple-animate will help everyone create more elegant UI with beautiful animation, and of course thanks for your time reading this and trying out the package. 🤘

Lastly, thanks

❤️ for contributing to the package and the blog post.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK