Skip to content

Commit 26e8ae7

Browse files
vaukalakFacebook Github Bot 4
authored andcommitted
added onComplete callback to animation config
Summary: This fix provides possibility to subscribe to a child animation lifecycle. You'll be able to observe every single animation: ``` Animated.sequence([ Animated.timing( this.state.scale, { toValue: 0, duration: 300, onComplete: () => this.setState({someProp: 'new value'}) } ), Animated.timing( this.state.scale, { toValue: 1, duration: 300 } ), ]).start(); ``` `state.someProp`, will updated with `'new value'` when the first animation will be completed. Closes #8494 Reviewed By: javache Differential Revision: D3735322 Pulled By: foghina fbshipit-source-id: fb69a4b993f7ab6a16da4fdd670e6c0b11c93517
1 parent 4ad01be commit 26e8ae7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Libraries/Animated/src/AnimatedImplementation.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Animated {
7474
type AnimationConfig = {
7575
isInteraction?: bool,
7676
useNativeDriver?: bool,
77+
onComplete?: ?EndCallback,
7778
};
7879

7980
// Important note: start() and stop() will only be called at most once.
@@ -1676,6 +1677,16 @@ var modulo = function(
16761677
return new AnimatedModulo(a, modulus);
16771678
};
16781679

1680+
const _combineCallbacks = function(callback: ?EndCallback, config : AnimationConfig) {
1681+
if (callback && config.onComplete) {
1682+
return (...args) => {
1683+
config.onComplete && config.onComplete(...args);
1684+
callback && callback(...args);
1685+
};
1686+
} else {
1687+
return callback || config.onComplete;
1688+
}
1689+
};
16791690

16801691
var maybeVectorAnim = function(
16811692
value: AnimatedValue | AnimatedValueXY,
@@ -1707,6 +1718,7 @@ var spring = function(
17071718
): CompositeAnimation {
17081719
return maybeVectorAnim(value, config, spring) || {
17091720
start: function(callback?: ?EndCallback): void {
1721+
callback = _combineCallbacks(callback, config);
17101722
var singleValue: any = value;
17111723
var singleConfig: any = config;
17121724
singleValue.stopTracking();
@@ -1735,6 +1747,7 @@ var timing = function(
17351747
): CompositeAnimation {
17361748
return maybeVectorAnim(value, config, timing) || {
17371749
start: function(callback?: ?EndCallback): void {
1750+
callback = _combineCallbacks(callback, config);
17381751
var singleValue: any = value;
17391752
var singleConfig: any = config;
17401753
singleValue.stopTracking();
@@ -1763,6 +1776,7 @@ var decay = function(
17631776
): CompositeAnimation {
17641777
return maybeVectorAnim(value, config, decay) || {
17651778
start: function(callback?: ?EndCallback): void {
1779+
callback = _combineCallbacks(callback, config);
17661780
var singleValue: any = value;
17671781
var singleConfig: any = config;
17681782
singleValue.stopTracking();

0 commit comments

Comments
 (0)