使用 React Native 一次启动多个 Animated.timing [英] Start multiple Animated.timing at once with React Native

查看:81
本文介绍了使用 React Native 一次启动多个 Animated.timing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一次启动多个 React Native 动画,所有动画都有一个回调.该示例工作正常,但我不喜欢这样一个事实,即我必须一个接一个地开始并且只有一个带有回调的动画.有没有更优雅的方式?

I'm trying to start multiple React Native animations at once, with one callback for all animations. The example works fine, but I don't like the fact, that I have to start one after the other and having only one animation with a callback. Is there a more elegant way?

Animated.timing(this.state.opacity, {
    toValue: 0,
    duration: 300
}).start();

Animated.timing(this.state.height, {
    toValue: 0,
    duration: 300
}).start(() => {
    // callback
});

推荐答案

是的,有.您可以使用 Animated.parallel

Yes, there is. You can use Animated.parallel!

Animated.parallel([
    Animated.timing(this.state.opacity, {
        toValue: 0,
        duration: 300
    }),
    Animated.timing(this.state.height, {
        toValue: 0,
        duration: 300
    })
]).start(() => {
    // callback
});

这篇关于使用 React Native 一次启动多个 Animated.timing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆