react-native动画的坑

在实现一个循环滚动的React-Native动画时,遇到问题。由于将Animated.Image误改为Image并忘记改回,导致在Animated.timing方法中访问this.spinValueOne时报错:'Attempted to assign to readonly property.'。该错误提示表明尝试修改了一个只读属性。解决方案是确保 Animated.timing 对应的组件是Animated组件。

准备做一个循环上下滚动的react-native动画,但是遇到了坑.我在调试的过程中把Animated.Image改成了Image,然后忘了改过来:
spinAniamte = ()=> {
if (this.animateToValue >= carmaHeight){
this.animateToValue = 0;
} else {
this.animateToValue = carmaHeight;
}
Animated.timing( // 随时间变化而执行的动画类型
this.spinValueOne, // 动画中的变量值
{
toValue: this.animateToValue, // 透明度最终变为1,即完全不透明
duration:2000,
}
).start((finished)=>{
return this.spinAniamte();
});
}

componentDidMount() {
  this.spinAniamte();
}

  render(){
      return (
        <View style={{flex:1,justifyContent:'center'}}>
            <Image  capInsets={{top:20,right:20,left:20,bottom:20}} source={{uri:'scan_border'}} style={{alignItems:'center',position:"absolute",left:carmaLeft,right:carmaLeft,height:carmaHeight}} resizeMode={'stretch'}>
                <Image source={{uri:'scanLine'}} style={{position:"absolute",top:this.spinValueOne,height:7,width:200}}></Animated.Image>
            </Image>
        </View>
    );
}

结果到Animated.timing方法里面去访问 this.spinValueOne会一直报错:
Attempted to assign to readonly property.截图:
这里写图片描述

如果Animated.timing,没有对应的Animated组件就会报这种错!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值