Skip to content

Commit bcadcbe

Browse files
authored
fix(animations): avoid steady mem consumption rise (NativeScript#6004)
1 parent a37da87 commit bcadcbe

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tns-core-modules/ui/animation/keyframe-animation.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
106106
}
107107
}
108108

109-
animations.map(a => a["curve"] ? a : Object.assign(a, {curve: info.curve}));
109+
animations.map(a => a["curve"] ? a : Object.assign(a, { curve: info.curve }));
110110

111111
const animation: KeyframeAnimation = new KeyframeAnimation();
112112
animation.delay = info.delay;
@@ -230,9 +230,19 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
230230
}
231231
}
232232
else {
233-
let animationDef = this.animations[index];
234-
(<any>animationDef).target = view;
235-
let animation = new Animation([animationDef]);
233+
let animation;
234+
const cachedAnimation = this._nativeAnimations[index - 1];
235+
236+
if (cachedAnimation) {
237+
animation = cachedAnimation;
238+
}
239+
else {
240+
let animationDef = this.animations[index];
241+
(<any>animationDef).target = view;
242+
animation = new Animation([animationDef]);
243+
this._nativeAnimations.push(animation);
244+
}
245+
236246
// Catch the animation cancel to prevent unhandled promise rejection warnings
237247
animation.play().then(() => {
238248
this.animate(view, index + 1, iterations);
@@ -241,7 +251,6 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
241251
}).catch((error: any) => {
242252
traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn);
243253
}); // tslint:disable-line
244-
this._nativeAnimations.push(animation);
245254
}
246255
}
247256

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy