ReactNativeReact Native学习

React Native 动画之 Animated.Sequen

2019-03-21  本文已影响0人  Kevin_小飞象

Animated提供了三种动画类型。每种动画类型都提供了特定的函数曲线,用于控制动画值从初始值变化到最终值的变化过程:

动画还可以使用组合函数以复杂的方式进行组合:

Animated.Sequence()

效果图

animated04.jpg

实例代码

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Animated,
  Text,
} from 'react-native';

const arr = [];
for (var i = 0; i < 50; i++) { 
  arr.push(i)
}
export default class App extends Component {
  constructor(props) {  //构造函数
    super(props);
    this.animatedValue = [];
    arr.forEach((value) => {
      this.animatedValue[value] = new Animated.Value(0);
    });
  }

  componentDidMount() { 
    this.animate();
  }

  animate() { 
    const animations = arr.map((item) => {
      return Animated.timing(
        this.animatedValue[item],
        {
          toValue: 1,
          duration: 50
        }
      )
    });
    Animated.sequence(animations).start();
  }

  render() {
    const animations = arr.map((a, i) => { 
      return <Animated.View
        key={i}
        style={{
          opacity: this.animatedValue[a],
          height: 40,
          width: 40,
          backgroundColor: 'blue',
          marginLeft: 5,
          marginTop:5  
        }}
      />
    })

    return (
      <View style={styles.container}>
        {animations}
      </View>

    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    flexWrap:'wrap',
  },

});
上一篇下一篇

猜你喜欢

热点阅读