From 65027e8e29d9e2f837b0f60f0a96a8b50bad1d64 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Mon, 6 Jul 2015 14:59:53 -0700 Subject: [PATCH] [ReactNative] Fix timeout edge-case in POPAnimation hack --- Libraries/Animation/POPAnimationMixin.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Libraries/Animation/POPAnimationMixin.js b/Libraries/Animation/POPAnimationMixin.js index bf95f41bf..0e109062c 100644 --- a/Libraries/Animation/POPAnimationMixin.js +++ b/Libraries/Animation/POPAnimationMixin.js @@ -36,6 +36,7 @@ var POPAnimationMixin = { AnimationProperties: POPAnimation.Properties, getInitialState: function(): Object { + this._popAnimationEnqueuedAnimationTimeouts = []; return { _currentAnimationsByNodeHandle: {}, }; @@ -120,10 +121,11 @@ var POPAnimationMixin = { } doneCallback && doneCallback(finished); }; - // Hack to aviod race condition. This delay should be imperceptible: - setTimeout(() => { + // Hack to aviod race condition in POP: + var animationTimeoutHandler = setTimeout(() => { POPAnimation.addAnimation(nodeHandle, animID, cleanupWrapper); - }, 10); + }, 1); + this._popAnimationEnqueuedAnimationTimeouts.push(animationTimeoutHandler); }, /** @@ -254,6 +256,10 @@ var POPAnimationMixin = { // Cleanup any potentially leaked animations. componentWillUnmount: function() { this.stopAllAnimations(); + this._popAnimationEnqueuedAnimationTimeouts.forEach(animationTimeoutHandler => { + clearTimeout(animationTimeoutHandler); + }); + this._popAnimationEnqueuedAnimationTimeouts = []; } };