Update running animations (#7196)

This commit is contained in:
Jukka Kurkela 2020-03-15 01:20:59 +02:00 committed by GitHub
parent da6056c8d1
commit b73b8f9863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -42,6 +42,19 @@ export default class Animation {
return this._active;
}
update(cfg, to, date) {
const me = this;
if (me._active) {
const currentValue = me._target[me._prop];
const elapsed = date - me._start;
const remain = me._duration - elapsed;
me._start = date;
me._duration = Math.floor(Math.max(remain, cfg.duration));
me._to = resolve([cfg.to, to, currentValue, cfg.from]);
me._from = resolve([cfg.from, currentValue, to]);
}
}
cancel() {
const me = this;
if (me._active) {

View File

@ -147,6 +147,7 @@ export default class Animations {
const animations = [];
const running = target.$animations || (target.$animations = {});
const props = Object.keys(values);
const date = Date.now();
let i;
for (i = props.length - 1; i >= 0; --i) {
@ -161,11 +162,17 @@ export default class Animations {
}
const value = values[prop];
let animation = running[prop];
if (animation) {
animation.cancel();
}
const cfg = animatedProps.get(prop);
if (animation) {
if (cfg && animation.active()) {
// There is an existing active animation, let's update that
animation.update(cfg, value, date);
continue;
} else {
animation.cancel();
}
}
if (!cfg || !cfg.duration) {
// not animated, set directly to new value
target[prop] = value;

View File

@ -343,7 +343,6 @@ export default class Chart {
options.onResize(me, newSize);
}
me.stop();
me.update('resize');
}
}