Build good-looking and smooth animated arcs in React Native with ReanimatedArc library.
Circular UI elements are a common pattern in many modern apps. They are usually used to indicate some kind of progress, for example
- your bank account balance,
- time passing on a stopwatch in your smartphone,
- macronutrient ratio in your diet,
and many more.
They are used whenever we want to show that something is a part of the whole. A circle seems to be the most natural way of representing this relationship.
However, rendering a circle is not trivial in <rte-code>react-native<rte-code>. One of the possibilities is to use <rte-code>react-native-svg<rte-code> with some math calculations. But what if we also want to:
- Animate our arc
- Animate it with native performance
- Control the progress with gestures
This is when our new library - ReanimatedArc comes into play.
ReanimatetdArc for the rescue!
Reanimated-arc is a utility component to build various UI elements that consist of arcs with the ability to animate the rendered arc. You can use a high-level wrapper that would animate the arc based on prop value change or low-level component to control your animation with react-native-reanimated. It can be also combined together with react-native-gesture-handler to build outstanding sliders. Also, thanks to the ReanimatedArc library the animations are very smooth.
Now, let's find out what we can build with the new library!
Circular Progress Bar
This is the most obvious usage of ReanimatedArc. To build circular progress we have to combine two arcs:
- the first will be used for background
- the second will be used to indicate progress.
We will interpolate an animated value into the text to show the percentage of the progress. This example can be found in the repository.
Donut charts are a great way of representing various kinds of data. For example, it may show macronutrients in a particular meal in some health apps. Also, it can display the ratio of your spendings in a particular month compared to the remaining funds in your bank’s app.
The example below shows a nicely animated donut chart. You can find the code here.
What’s more, ReanimatedArc allows you to build a simple stopwatch. This type of chart can also be used in various projects like, for example, workout apps.
You can check this example here.
The rounded slider is commonly used as a component for adjusting some settings. Let's imagine that you have a Smart Home. Your smartphone is a command center in your hand. One of your smart devices is a light bulb with adjustable brightness. Imagine how awesome it would be to dim your light with a nice-looking rounded slider… No problem.
Check slider implementation here.
To sum up, ReanimatedArc library allows you to build good-looking and smooth animated arcs. They can be used in many different types of applications such as banking, sports, Smart Home or diet apps.
I hope that this library will be helpful to you. If you like the project don't forget to give it a star on GitHub.