【发布时间】:2017-05-23 07:55:03
【问题描述】:
我正在尝试使用一些图像创建一个反应原生动画,作为这样的倒计时:
3 --> ease out down duration 1 second each case
2 --> ease out down
1 --> ease out down
我找到了一种使用 react animatable 的方法,但结果并不能说服我,如果有更好的方法,请告诉我。
我认为每次我遇到元素的新渲染时都会开始倒计时,我会说要对动画做出反应,以便为每个更改图像编号的数字减少 3 次迭代,这不是解决问题的自然方法我有。
暂时没有使用redux,可能以后我会添加它。 状态属性:时间、当前开始时间尚未使用。
我所需要的只是我展示的图像在一个定义明确的动画中发生倒计时的效果。
我认为快到了,但肯定有更好的方法来解决这个问题,任何建议都会得到很好的接受,即使它只是作为指导。我也尝试过 react-native-animate-number 但没有运气......
提前致谢
import React from 'react';
import util from '../utils.js';
import * as Animatable from 'react-native-animatable';
import {
View,
Dimensions,
Image,
StyleSheet
} from 'react-native';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
const styles = StyleSheet.create({
mainOption: {
},
container: {
width: width,
height: height,
flex: 1,
justifyContent: 'center',
flexDirection: 'column',
alignItems: 'center'
}
});
const timeLapse = [
<Image source={require('../images/1.png')} key={util.uniqueId()}/>,
<Image source={require('../images/2.png')} key={util.uniqueId()}/>,
<Image source={require('../images/3.png')} key={util.uniqueId()}/>
];
export default class StartingGameCountDown extends React.Component {
constructor(props) {
super(props);
this.state = {
time: props.time,
currentTimeToBegin: props.currentTimeToBegin,
imagePosition: 0
};
}
componentWillReceiveProps(nextProps) {
const nextImage = this.state.imagePosition + 1;
this.setState({
...this.state,
letters: nextProps.time,
currentTimeToBegin: nextProps.currentTimeToBegin,
imagePosition: nextImage
});
}
render() {
return (
<View style={styles.container}>
<Animatable.View
ref='countDown'
duration={1000}
delay={0}
iterationCount={3}
animation="fadeOutDown"
style={styles.mainOption}>
{timeLapse[this.state.imagePosition]}
</Animatable.View>
</View>
);
}
}
【问题讨论】:
标签: javascript reactjs animation react-native react-animated