concept animate value in category react native

appears as: nimated values, n animated value, imated value, imated values
React Native in Action

This is an excerpt from Manning's book React Native in Action.

Listing 7.1 Using Animated and updating the marginTop property
import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Animated,    #1  
  Button
} from 'react-native';

export default class RNAnimations extends Component {
  marginTop = new Animated.Value(20);    #2  
  animate = () => {    #3  
    Animated.timing(
      this.marginTop,
      {
        toValue: 200,
        duration: 500,
      }
    ).start();
  }
  render() {
    return (
      <View style={styles.container}>
        <Button    #4  
          title='Animate Box'
          onPress={this.animate}
        />
        <Animated.View 
          style={[styles.box, { marginTop: this.marginTop } ]} />    #5  
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 10,
    paddingTop: 50,
  },
  box: {
    width: 150,
    height: 150,
    backgroundColor: 'red'
  }
});

#1   Imports the Animated API from React Native
#2   Creates a class property called marginTop and assigns it to an animated value, passing in the starting value (20 in this case)
#3   Creates a function that will animate the value
#4   Attach the animate method to an onPress handler so you can call it
#5   Use the Animated.View component instead of the regular View component