Animate Multiple Animations at the Same Time with Animated.parallel

Jason Brown
InstructorJason Brown
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 6 years ago

In this lesson we'll use Animated.parallel to animate multiple Animated.timing and Animated.spring animations at the same time.

[00:00] We'll start by importing Animated from React Native. Next, we'll create a componentWillMount life cycle method, then we'll create two animated values. this.animatedValue1 = new Animated.Value which will set the default value of 0And, this.animatedValue2, which will be a default value of one.

[00:20] Next, we'll set up our styles by creating a variable called animatedStyles, which we'll assign it object with the property transform, which takes an array. Our first transform, we'll translate Y, and we'll give it this.animatedValue1, and our second will be scale, which we'll give our second animation this.animatedValue2.

[00:39] Then we'll play our new style, but first we need to change our regular view to an Animated.View, and then, give it our new style. We'll create a componentWillMount life cycle method, and use Animated.Parallel, which takes an array of multiple animations. We'll add Animated.timing, and give it this.animatedValue1, and animate to 500 over the course of 300 milliseconds. Then, our second animation, we'll roll in Animated.Spring, we have this.animatedValue2, and spring to 3.

[01:16] Now, if we call Start on our Parallel, and refresh our emulator, we can see that it translated Y to 500 over 300 milliseconds, and scaled to 3 at the same time.