ReactNative系列之二十一仿微信发语音空消息

在iOS上的微信发语音时,会先出现一个渐变颜色循环的动画效果。图为效果,代码向下看:

移步代码区:

主要的动画使用Animated.timing,将透明度1->0.3->1不停的播放

    startAnimation() {
        this.state.fadeOutOpacity.setValue(1);

        this._animated = Animated.sequence([  //  组合动画 parallel(同时执行)、sequence(顺序执行)、stagger(错峰,其实就是插入了delay的parrllel)和delay(延迟)

                    Animated.timing(
                        this.state.fadeOutOpacity,
                        {
                            toValue: 0.3,
                            duration: 2000,
                            easing: Easing.linear, // 线性的渐变函数
                        }
                    ),
                    Animated.timing(
                        this.state.fadeOutOpacity,
                        {
                            toValue: 1,
                            duration: 2000,
                            easing: Easing.linear, // 线性的渐变函数
                        }
                    ),
                ]); // 循环执行动画
    // .start(() => this.startAnimation())
        this._animated.start(() => this.startAnimation());
        this.state.fadeOutOpacity.addListener((state) => {
            console.log("fadeOutOpacity=>" + state.value);
        });
    }

在render()方法中可以这样使用

<Animated.View    // 可选的基本组件类型: Image, Text, View(可以包裹任意子View)
    style={{
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        opacity: this.state.fadeOutOpacity, // 透明度
        width: 100,
        height: 40,
    }}>
    <View style={{backgroundColor: 'white', width: 100, height: 40, borderRadius: 5,
        borderWidth: 0.5,
        borderColor: "#7FB25A",}}/>
</Animated.View>

启动动画的地方可以

    componentDidMount() {
        this.startAnimation();
    }

结束动画

this._animated.stop((value) => {
                        console.log("yeputi_wk", "动画停止" + value)
                    },
                )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值