This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Animate Multiple Animations at the Same Time with Animated.parallel

1:26 React lesson by

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

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

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

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 0. And, this.animatedValue2, which will be a default value of one.

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.

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.

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?