From 3b11d5d10e0f117e4e603ca35df2b3849e2397f7 Mon Sep 17 00:00:00 2001 From: Tsvetan Raikov Date: Mon, 18 Apr 2016 13:42:42 +0300 Subject: [PATCH] Fixed: There is a crash in Android when running animations too fast --- ui/animation/keyframe-animation.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ui/animation/keyframe-animation.ts b/ui/animation/keyframe-animation.ts index 3beb36af6..4352e1267 100644 --- a/ui/animation/keyframe-animation.ts +++ b/ui/animation/keyframe-animation.ts @@ -35,7 +35,7 @@ export class KeyframeAnimation { private _reject; private _isPlaying: boolean; private _isForwards: boolean; - private _currentAnimation: animationModule.Animation; + private _nativeAnimations: Array; public static keyframeAnimationFromInfo(info: KeyframeAnimationInfo, valueSourceModifier: number) { let animations = new Array(); @@ -102,10 +102,11 @@ export class KeyframeAnimation { public cancel() { if (this._isPlaying) { - if (this._currentAnimation && this._currentAnimation.isPlaying) { - this._currentAnimation.cancel(); - } this._isPlaying = false; + for (let i = this._nativeAnimations.length - 1; i >= 0; i--) { + let animation = this._nativeAnimations[i]; + animation.cancel(); + } this._rejectAnimationFinishedPromise(); } } @@ -121,6 +122,7 @@ export class KeyframeAnimation { }); this._isPlaying = true; + this._nativeAnimations = new Array(); if (this.delay !== 0) { let that = this; @@ -134,6 +136,9 @@ export class KeyframeAnimation { } private animate(view: view.View, index: number, iterations: number) { + if (!this._isPlaying) { + return; + } if (index === 0) { let animation = this.animations[0]; let modifier = animation["valueSource"]; @@ -196,19 +201,19 @@ export class KeyframeAnimation { animation.play().then(() => { this.animate(view, index + 1, iterations); }); - this._currentAnimation = animation; + this._nativeAnimations.push(animation); } } public _resolveAnimationFinishedPromise() { + this._nativeAnimations = new Array(); this._isPlaying = false; - this._currentAnimation = undefined; this._resolve(); } public _rejectAnimationFinishedPromise() { + this._nativeAnimations = new Array(); this._isPlaying = false; - this._currentAnimation = undefined; this._reject(new Error("Animation cancelled.")); } }