Now, for a quick prototype we can have a look at how we can animate an element in react-native
. Weβre going to use a
ball and slide it in from the top left of the screen to the bottom right. This is not the most spectacular animation we
could add but it will help us understand how animated views work.
The main idea with animation is that we need to go through the mental model of figuring out 3 things:
Animated.spring(springAnim, {
toValue: { x: 200, y: 500 },
useNativeDriver: true, // use this for accessing native performance animations
}).start()
Animated.View
, in our case a very simple component, a View
that
represents the bouncy ball we want to displayThe way react
and state works is this in a nutshell.
Animation components are special as they donβt go through this pipeline but rather through the yoga
layout engine we
mentioned earlier. The component will not re-render on any of the intermediary animation steps and there are no
callbacks to state when animating a component. That is why it is better to use Animated
instead of using state to
change the visual aspect of your components if that is an option.