Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start multiple Animated.timing at once with 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
});
like image 634
Sebastian Templin Avatar asked Dec 01 '16 01:12

Sebastian Templin


1 Answers

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
});
like image 193
tomatentobi Avatar answered Sep 27 '22 13:09

tomatentobi