代码之家  ›  专栏  ›  技术社区  ›  Mahdi Bashirpour

在react native render文本组件中显示动画值

  •  2
  • Mahdi Bashirpour  · 技术社区  · 6 年前

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

    固定冲突:对象作为反应子级无效(找到:具有键值的对象)。如果要呈现子集合,请改用数组。

    当然,我看到了 console

    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>
        );
    
    }
    
    1 回复  |  直到 6 年前
        1
  •  6
  •   Tholle    6 年前

    addListener value progress

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