我无法在Render中显示Animated的值,而且会返回以下错误。
Invariant Violation: Objects are not valid as a React child (found: object with keys {value}). If you meant to render a collection of children, use an array instead.
当然,我可以在控制台中看到Value的值。
constructor(props) {
super(props);
this.state={
progress:0
}
this.animatedValue = new Animated.Value(0);
this.animatedValue.addListener((progress) => {
this.setState({progress})
});
}
componentDidMount() {
this.animate()
}
animate() {
this.animatedValue.setValue(0);
Animated.timing(
this.animatedValue,
{
toValue: 1,
duration: 15000,
easing: Easing.linear
}
).start()
}
render() {
return(
<View>
<Text> {this.state.progress} </Text>
</View>
);
}
setState
之前依赖于一个条件,例如if (Math.round(progress.value) !== this.state.progress)
。 - Nick Bull