Monday, June 3, 2024
37
rated 0 times [  38] [ 1]  / answers: 1 / hits: 17055  / 8 Years ago, thu, december 1, 2016, 12:00:00

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
});

More From » react-native

 Answers
37

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
});

[#59854] Tuesday, November 29, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braeden

Total Points: 231
Total Questions: 96
Total Answers: 86

Location: Somalia
Member since Mon, Dec 28, 2020
4 Years ago
;