From bcadcbe7b5761a0f6aea1b6252ea8af44bee1ca1 Mon Sep 17 00:00:00 2001 From: Martin Yankov Date: Wed, 4 Jul 2018 13:44:01 +0300 Subject: [PATCH] fix(animations): avoid steady mem consumption rise (#6004) --- .../ui/animation/keyframe-animation.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tns-core-modules/ui/animation/keyframe-animation.ts b/tns-core-modules/ui/animation/keyframe-animation.ts index be57131a0..2344499bd 100644 --- a/tns-core-modules/ui/animation/keyframe-animation.ts +++ b/tns-core-modules/ui/animation/keyframe-animation.ts @@ -106,7 +106,7 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition { } } - animations.map(a => a["curve"] ? a : Object.assign(a, {curve: info.curve})); + animations.map(a => a["curve"] ? a : Object.assign(a, { curve: info.curve })); const animation: KeyframeAnimation = new KeyframeAnimation(); animation.delay = info.delay; @@ -230,9 +230,19 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition { } } else { - let animationDef = this.animations[index]; - (animationDef).target = view; - let animation = new Animation([animationDef]); + let animation; + const cachedAnimation = this._nativeAnimations[index - 1]; + + if (cachedAnimation) { + animation = cachedAnimation; + } + else { + let animationDef = this.animations[index]; + (animationDef).target = view; + animation = new Animation([animationDef]); + this._nativeAnimations.push(animation); + } + // Catch the animation cancel to prevent unhandled promise rejection warnings animation.play().then(() => { this.animate(view, index + 1, iterations); @@ -241,7 +251,6 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition { }).catch((error: any) => { traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn); }); // tslint:disable-line - this._nativeAnimations.push(animation); } }