Rangle.io: React Native Workshop
gitbook
gitbook
  • Introduction
  • Setup
    • Hello World
    • Debugging
  • Core Concepts
    • Components
    • Styles
    • Flexbox
    • APIs
  • Navigation
    • Navigation Experimental
    • Creating Some Helpers
    • The Navigator Component
  • ListView (Pokédex)
    • List View
    • List View: Render Row
    • Text Input
    • Keyboard Spacer
  • Selectors (Filtering)
  • Animation
    • LayoutAnimation
    • Animated
      • Animated.Value
      • Timing, Spring & Decay
      • Animated Components
      • More Animated
    • Resources
    • Exercise
  • ScrollView (Pokemon Details)
  • MapView
  • Testing
  • Gesture Responder System
    • PanResponder
Powered by GitBook
On this page
  • Animated.timing
  • Animated.spring
  • Animated.decay

Was this helpful?

  1. Animation
  2. Animated

Timing, Spring & Decay

PreviousAnimated.ValueNextAnimated Components

Last updated 6 years ago

Was this helpful?

The three basic options to define the animation of an Animated.Value are:

Animated.timing

Used to define an animation that takes a specific amount of time to execute.

import { Animated, Easing } from 'react-native';
this.state = { animatedVal: new Animated.Value(0) };

Animated.timing(this.state.animatedVal, {
  toValue: 100,
  duration: 500,
  easing: Easing.inOut(Easing.ease),
  delay: 200,
}).start(() => console.log('animation complete'));

Animated.spring

Used to define an animation as a spring rather than a specific timing. The spring uses the same physics as .

import { Animated, Easing } from 'react-native';
this.state = { animatedVal: new Animated.Value(0) };

Animated.spring(this.state.animatedVal, {
  toValue: 100,
  friction: 7,
  tension: 40,
}).start(() => console.log('animation complete'));

Animated.decay

Used to define a deceleration style transition for something that is already moving.

import { Animated, Easing } from 'react-native';
this.state = { animatedVal: new Animated.Value(0) };

Animated.decay(this.state.animatedVal, {
  velocity: { // velocity from a gesture
    x: gestureState.vx,
    y: gestureState.vy,
  },
  deceleration: 0.997,
}).start(() => console.log('animation complete'));
Origami