Skip to content

Commit 098371a

Browse files
committed
perf(animation): only update progressStep once per 16ms
1 parent 22c32f3 commit 098371a

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ionic/animations/animation.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class Animation {
2626
private _rv: boolean;
2727
private _unregTrans: Function;
2828
private _tmr: any;
29+
private _lastUpd: number = 0;
2930

3031
public isPlaying: boolean;
3132
public hasTween: boolean;
@@ -174,7 +175,7 @@ export class Animation {
174175
};
175176

176177
if (typeof val === 'string' && val.indexOf(' ') < 0) {
177-
let r = val.match(/(^-?\d*\.?\d*)(.*)/);
178+
let r = val.match(cssValueRegex);
178179
let num = parseFloat(r[1]);
179180

180181
if (!isNaN(num)) {
@@ -600,17 +601,26 @@ export class Animation {
600601
}
601602

602603
progressStep(stepValue: number) {
603-
stepValue = Math.min(1, Math.max(0, stepValue));
604+
let now = Date.now();
604605

605-
for (var i = 0; i < this._c.length; i++) {
606-
this._c[i].progressStep(stepValue);
607-
}
606+
// only update if the last update was more than 16ms ago
607+
if (now - 16 > this._lastUpd) {
608+
this._lastUpd = now;
608609

609-
if (this._rv) {
610-
stepValue = ((stepValue * -1) + 1);
611-
}
610+
stepValue = Math.min(1, Math.max(0, stepValue));
612611

613-
this._progress(stepValue);
612+
for (var i = 0; i < this._c.length; i++) {
613+
this._c[i].progressStep(stepValue);
614+
}
615+
616+
if (this._rv) {
617+
// if the animation is going in reverse then
618+
// flip the step value: 0 becomes 1, 1 becomes 0
619+
stepValue = ((stepValue * -1) + 1);
620+
}
621+
622+
this._progress(stepValue);
623+
}
614624
}
615625

616626
progressEnd(shouldComplete: boolean, currentStepValue: number) {
@@ -765,4 +775,6 @@ const TRANSFORMS = {
765775
'skewX':1, 'skewY':1, 'perspective':1
766776
};
767777

778+
const cssValueRegex = /(^-?\d*\.?\d*)(.*)/;
779+
768780
let AnimationRegistry = {};

0 commit comments

Comments
 (0)