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 5 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.

egghead
egghead
~ 48 seconds ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today