使用带有React Native的Animated
动画会变得非常大并占用大量空间,尤其是如果你有几个动画。有没有办法将它们放在一个单独的文件中,如果是这样,它们将如何被调用?
Animated.sequence([
Animated.timing(this.state.move,{
toValue: {x: 50, y: 100},
duration:400
}),
Animated.timing(this.state.move,{
toValue: {x: 0, y: 0,
duration:400,delay:400
}),
]).start()
答案 0 :(得分:0)
好的,我想出了怎么做。创建一个单独的文件:
import React, { Component } from 'react';
import {
Animated,
} from 'react-native';
var Anims = {
firstAnim(move) {
Animated.sequence([
Animated.timing(move,{
toValue: {x: 50, y: 100},
duration:400
}),
Animated.timing(move,{
toValue: {x: 0, y: 0,
duration:400,delay:400
}),
]).start()
}
}
module.exports = Anims;
然后要求它:
const Animations=require('./animations.js');
并称之为:
Animations.firstAnim(this.state.move);