[英]Error while doing animations on react native
I'm having problem while trying to do animations on react native it throws an error that says I can't assign the x value.我在尝试在 React Native 上制作动画时遇到问题,它会抛出一个错误,提示我无法分配 x 值。 Anybody knows what can it be?
有谁知道它可以是什么?
undefined is not an object (evaluating '_this.state.animateXY.xinterpolate')
undefined 不是一个对象(评估'_this.state.animateXY.xinterpolate')
import {
View,
Text,
StyleSheet,
Animated,
Image,
Easing,
TouchableHighlight,
Dimensions,
} from 'react-native';
const {width, height} = Dimensions.get('window');
class AddPost extends Component {
constructor(){
super()
this.state ={
animate: new Animated.Value(30),
animateXY: new Animated.Value({x:0, y:0}),
// radius: new Animated.Value(0)
}
this.animateInterpolate = this.state.animateXY.x.interpolate({
inputRange: [0,150],
outputRange: [1,2]
})
}
componentWillMount(){
Animated.sequence([
Animated.timing(this.state.animateXY, {
toValue: {x: height / 2, y: 0},
duration:2000
}),
Animated.timing(this.state.animate, {
toValue: 60,
duration:2000
}),
/*Animated.timing(this.state.animate, {
toValue: 40,
duration:2000
}),*/
]).start()
}
render() {
return (
<TouchableHighlight onPress={onPress}>
<View style={styles.container}>
<Animated.View style={{
width: this.state.animate,
height: this.state.animate,
backgroundColor: 'blue',
position: 'absolute',
top: this.state.animateX.x,
left: this.state.animateY.y,
// transform:[{scale: this.animateInterpolate}],
borderRadius: this.state.radius
}}/>
</View>
</TouchableHighlight>
);
}
}
this.state.animateX
is simply not declared. this.state.animateX
根本没有声明。
You need to set animatedXY to 0 : animateX: new Animated.Value(0)
您需要将animatedXY 设置为0 :
animateX: new Animated.Value(0)
Then set your animation :然后设置你的动画:
Animated.timing(this.state.animateX, {
toValue: height/2,
duration:2000
}),
Then you can set the value of your X :然后你可以设置你的 X 的值:
top: this.state.animateX
Use Animated.使用动画。 ValueXY insted of Animated.Value
ValueXY 插入Animated.Value
animateX : new Animated.ValueXY({x: 0, y: 0});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.