[ReactNative] Fix timeout edge-case in POPAnimation hack

This commit is contained in:
Eric Vicenti 2015-07-06 14:59:53 -07:00
parent 3955236b0f
commit 65027e8e29
1 changed files with 9 additions and 3 deletions

View File

@ -36,6 +36,7 @@ var POPAnimationMixin = {
AnimationProperties: POPAnimation.Properties, AnimationProperties: POPAnimation.Properties,
getInitialState: function(): Object { getInitialState: function(): Object {
this._popAnimationEnqueuedAnimationTimeouts = [];
return { return {
_currentAnimationsByNodeHandle: {}, _currentAnimationsByNodeHandle: {},
}; };
@ -120,10 +121,11 @@ var POPAnimationMixin = {
} }
doneCallback && doneCallback(finished); doneCallback && doneCallback(finished);
}; };
// Hack to aviod race condition. This delay should be imperceptible: // Hack to aviod race condition in POP:
setTimeout(() => { var animationTimeoutHandler = setTimeout(() => {
POPAnimation.addAnimation(nodeHandle, animID, cleanupWrapper); POPAnimation.addAnimation(nodeHandle, animID, cleanupWrapper);
}, 10); }, 1);
this._popAnimationEnqueuedAnimationTimeouts.push(animationTimeoutHandler);
}, },
/** /**
@ -254,6 +256,10 @@ var POPAnimationMixin = {
// Cleanup any potentially leaked animations. // Cleanup any potentially leaked animations.
componentWillUnmount: function() { componentWillUnmount: function() {
this.stopAllAnimations(); this.stopAllAnimations();
this._popAnimationEnqueuedAnimationTimeouts.forEach(animationTimeoutHandler => {
clearTimeout(animationTimeoutHandler);
});
this._popAnimationEnqueuedAnimationTimeouts = [];
} }
}; };