fix(animations): error when setting position before starting animation (#28255)

it is now possible to set the position when the animation has not ever been started.

PR Close #28255
This commit is contained in:
Benjamin Kindle 2020-12-04 13:28:35 -05:00 committed by Andrew Scott
parent 09e1e1935a
commit 3b7d2ca179
2 changed files with 24 additions and 0 deletions

View File

@ -156,6 +156,9 @@ export class WebAnimationsPlayer implements AnimationPlayer {
}
setPosition(p: number): void {
if (this.domPlayer === undefined) {
this.init();
}
this.domPlayer.currentTime = p * this.time;
}

View File

@ -67,6 +67,27 @@ import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animat
player.finish();
expect(log).toEqual(['started', 'done']);
});
it('should allow setting position before animation is started', () => {
const player = new WebAnimationsPlayer(element, [], {duration: 1000});
player.setPosition(0.5);
const p = innerPlayer!;
expect(p.log).toEqual(['pause']);
expect(p.currentTime).toEqual(500);
});
it('should continue playing animations from setPosition', () => {
const player = new WebAnimationsPlayer(element, [], {duration: 1000});
player.play();
const p = innerPlayer!;
expect(p.log).toEqual(['play']);
player.setPosition(0.5);
expect(p.currentTime).toEqual(500);
expect(p.log).toEqual(['play']);
});
});
}