feat(animations): introduce a wave of new animation features

This commit is contained in:
Matias Niemelä
2017-04-26 10:44:28 -07:00
committed by Jason Aden
parent d761059e4d
commit 16c8167886
55 changed files with 7732 additions and 2217 deletions

View File

@ -15,6 +15,10 @@ import {AnimationDriver} from '../../src/render/animation_driver';
export class MockAnimationDriver implements AnimationDriver {
static log: AnimationPlayer[] = [];
computeStyle(element: any, prop: string, defaultValue?: string): string {
return defaultValue || '';
}
animate(
element: any, keyframes: {[key: string]: string | number}[], duration: number, delay: number,
easing: string, previousPlayers: any[] = []): MockAnimationPlayer {
@ -30,8 +34,10 @@ export class MockAnimationDriver implements AnimationDriver {
*/
export class MockAnimationPlayer extends NoopAnimationPlayer {
private __finished = false;
private __started = false;
public previousStyles: {[key: string]: string | number} = {};
private _onInitFns: (() => any)[] = [];
public currentSnapshot: ɵStyleData = {};
constructor(
public element: any, public keyframes: {[key: string]: string | number}[],
@ -40,10 +46,12 @@ export class MockAnimationPlayer extends NoopAnimationPlayer {
super();
previousPlayers.forEach(player => {
if (player instanceof MockAnimationPlayer) {
const styles = player._captureStyles();
Object.keys(styles).forEach(prop => { this.previousStyles[prop] = styles[prop]; });
const styles = player.currentSnapshot;
Object.keys(styles).forEach(prop => this.previousStyles[prop] = styles[prop]);
}
});
this.totalTime = delay + duration;
}
/* @internal */
@ -66,7 +74,17 @@ export class MockAnimationPlayer extends NoopAnimationPlayer {
this.__finished = true;
}
private _captureStyles(): {[styleName: string]: string | number} {
/* @internal */
triggerMicrotask() {}
play(): void {
super.play();
this.__started = true;
}
hasStarted() { return this.__started; }
beforeDestroy() {
const captures: ɵStyleData = {};
Object.keys(this.previousStyles).forEach(prop => {
@ -86,6 +104,6 @@ export class MockAnimationPlayer extends NoopAnimationPlayer {
});
}
return captures;
this.currentSnapshot = captures;
}
}