gpt4 book ai didi

javascript - 在 React Native 渲染文本组件中显示动画值

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:39:40 24 4
gpt4 key购买 nike

我无法在渲染器上显示动画值并返回此错误。

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.

当然,我在console中看到了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>
);

}

最佳答案

赋予 addListener 的函数将使用一个以 value 键作为参数的对象来调用,因此不用将 progress 设置为整个对象,请改用 value:

this.animatedValue.addListener((progress) => {
this.setState({ progress: progress.value });
});

关于javascript - 在 React Native 渲染文本组件中显示动画值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51160886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com