Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Animate Multiple Animations at the Same Time with Animated.parallel

    Jason BrownJason Brown

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

    react-nativeReact Native
    0.35 - 0.39
    reactReact
    ^15.0.0
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss