私はプレスでビューをアニメートしたいと思います。反応したネイティブでアニメーション化されたアニメーション
export default class AnimatedRotation extends React.Component {
constructor(props) {
super(props);
this.state = {
spinValue: new Animated.Value(0),
color: '#F62459',
}
}
rotateSpring =() => {
Animated.spring(
this.state.spinValue,
{
toValue: 1,
friction: 1,
}
).start();
this.setState({
color: this.state.color == '#F62469' ? '#FFC107' : '#F62469',
})
};
render() {
var spin = this.state.spinValue.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg'],
});
return (
<View style={styles.container}>
<Text style={styles.header}>Header</Text>
<View style={styles.wrapper}>
<TouchableWithoutFeedback onPress={this.rotateSpring}>
<Animated.View style={[styles.circle, {
transform: [{rotate: spin},],
backgroundColor: this.state.color
}]}>
<Icon name="ios-add" color="white" size={50}/>
</Animated.View>
</TouchableWithoutFeedback>
</View>
</View>
);
}
}
私はアニメーションを1回だけ押して、もう一度アニメーションしません。私はその理由は、spinValue
の状態が初めて押されたときのtoValue
と等しいからです。だから私はこのような何かを考えた:
rotateSpring =() => {
Animated.spring(
this.state.spinValue,
{
toValue: this.state.spinValue + 1,
friction: 1,
}
).start();
this.setState({
color: this.state.color == '#F62469' ? '#FFC107' : '#F62469',
spinValue: this.state.spinValue + 1,
})
};
しかし、これは、アプリケーションがクラッシュします。 onPressに何かアニメーションを付けるには?