React Native Animation
React Native Animations provide extra effects and great user experience in the app. Animations convey physically believable motion in your interface.
There are two types of complementary animation systems in React Native. These are:
Animated exports four different animated component as View, Text Image and ScrollView. We can also create our own animated component using Animated.createAnimatedComponent().
React Native Animation Example 1 (Animated.timing())
In this example, we will create a spinning animation on image using Animated.timing().
The interpolate() method call any Animated.Value. It interpolates the value before updating the property. In above example, we map 0 (zero) degrees to 360 degrees.
We pass an inputRange [0,1] and get the outputRange[?0deg?, ?360deg?] array.
React Native Animation Example 2 (Animated.timing())
In this example, we declare a single animated value this.aninatedValue and use it with interpolate to create multiple animations, such as: marginLeft, opacity, fontSize, and rotate. We will interpolate this property for styling such as opacity, margins, text sizes, and rotation properties.
LayoutAnimation allows to globally configure create and update animations. This will be used for all views in the next render/layout cycle.
The LayoutAnimation is quite useful, it has much less control than Animated and other animation libraries.
To use this API in Android we need to set the following flags via UIManager:
React Native LayoutAnimation Example
In this example, we create a TouchableOpacity and a View component. Pressing the TouchableOpacity component calls the _onPress() method and it animates the View component by increases the width and height of View by 15 unit.