mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
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 https://github.com/facebook/react-native/pull/8494 Reviewed By: javache Differential Revision: D3735322 Pulled By: foghina fbshipit-source-id: fb69a4b993f7ab6a16da4fdd670e6c0b11c93517
This commit is contained in:
parent
4ad01be3a0
commit
26e8ae74b6
@ -74,6 +74,7 @@ class Animated {
|
||||
type AnimationConfig = {
|
||||
isInteraction?: bool,
|
||||
useNativeDriver?: bool,
|
||||
onComplete?: ?EndCallback,
|
||||
};
|
||||
|
||||
// Important note: start() and stop() will only be called at most once.
|
||||
@ -1676,6 +1677,16 @@ var modulo = function(
|
||||
return new AnimatedModulo(a, modulus);
|
||||
};
|
||||
|
||||
const _combineCallbacks = function(callback: ?EndCallback, config : AnimationConfig) {
|
||||
if (callback && config.onComplete) {
|
||||
return (...args) => {
|
||||
config.onComplete && config.onComplete(...args);
|
||||
callback && callback(...args);
|
||||
};
|
||||
} else {
|
||||
return callback || config.onComplete;
|
||||
}
|
||||
};
|
||||
|
||||
var maybeVectorAnim = function(
|
||||
value: AnimatedValue | AnimatedValueXY,
|
||||
@ -1707,6 +1718,7 @@ var spring = function(
|
||||
): CompositeAnimation {
|
||||
return maybeVectorAnim(value, config, spring) || {
|
||||
start: function(callback?: ?EndCallback): void {
|
||||
callback = _combineCallbacks(callback, config);
|
||||
var singleValue: any = value;
|
||||
var singleConfig: any = config;
|
||||
singleValue.stopTracking();
|
||||
@ -1735,6 +1747,7 @@ var timing = function(
|
||||
): CompositeAnimation {
|
||||
return maybeVectorAnim(value, config, timing) || {
|
||||
start: function(callback?: ?EndCallback): void {
|
||||
callback = _combineCallbacks(callback, config);
|
||||
var singleValue: any = value;
|
||||
var singleConfig: any = config;
|
||||
singleValue.stopTracking();
|
||||
@ -1763,6 +1776,7 @@ var decay = function(
|
||||
): CompositeAnimation {
|
||||
return maybeVectorAnim(value, config, decay) || {
|
||||
start: function(callback?: ?EndCallback): void {
|
||||
callback = _combineCallbacks(callback, config);
|
||||
var singleValue: any = value;
|
||||
var singleConfig: any = config;
|
||||
singleValue.stopTracking();
|
||||
|
Loading…
x
Reference in New Issue
Block a user