fix(animations): allow animations to be destroyed manually (#12719)

Closes #12456
Closes #12719
This commit is contained in:
Matias Niemelä
2016-11-08 16:21:28 -08:00
committed by vikerman
parent ad3bf6c54f
commit fe35bc34f6
8 changed files with 175 additions and 121 deletions

View File

@ -15,6 +15,7 @@ export class AnimationGroupPlayer implements AnimationPlayer {
private _onStartFns: Function[] = [];
private _finished = false;
private _started = false;
private _destroyed = false;
public parentPlayer: AnimationPlayer = null;
@ -38,9 +39,6 @@ export class AnimationGroupPlayer implements AnimationPlayer {
private _onFinish() {
if (!this._finished) {
this._finished = true;
if (!isPresent(this.parentPlayer)) {
this.destroy();
}
this._onDoneFns.forEach(fn => fn());
this._onDoneFns = [];
}
@ -76,11 +74,19 @@ export class AnimationGroupPlayer implements AnimationPlayer {
}
destroy(): void {
this._onFinish();
this._players.forEach(player => player.destroy());
if (!this._destroyed) {
this._onFinish();
this._players.forEach(player => player.destroy());
this._destroyed = true;
}
}
reset(): void { this._players.forEach(player => player.reset()); }
reset(): void {
this._players.forEach(player => player.reset());
this._destroyed = false;
this._finished = false;
this._started = false;
}
setPosition(p: any /** TODO #9100 */): void {
this._players.forEach(player => { player.setPosition(p); });

View File

@ -16,7 +16,8 @@ export class AnimationSequencePlayer implements AnimationPlayer {
private _onDoneFns: Function[] = [];
private _onStartFns: Function[] = [];
private _finished = false;
private _started: boolean = false;
private _started = false;
private _destroyed = false;
public parentPlayer: AnimationPlayer = null;
@ -48,9 +49,6 @@ export class AnimationSequencePlayer implements AnimationPlayer {
private _onFinish() {
if (!this._finished) {
this._finished = true;
if (!isPresent(this.parentPlayer)) {
this.destroy();
}
this._onDoneFns.forEach(fn => fn());
this._onDoneFns = [];
}
@ -79,13 +77,18 @@ export class AnimationSequencePlayer implements AnimationPlayer {
pause(): void { this._activePlayer.pause(); }
restart(): void {
this.reset();
if (this._players.length > 0) {
this.reset();
this._players[0].restart();
}
}
reset(): void { this._players.forEach(player => player.reset()); }
reset(): void {
this._players.forEach(player => player.reset());
this._destroyed = false;
this._finished = false;
this._started = false;
}
finish(): void {
this._onFinish();
@ -93,8 +96,11 @@ export class AnimationSequencePlayer implements AnimationPlayer {
}
destroy(): void {
this._onFinish();
this._players.forEach(player => player.destroy());
if (!this._destroyed) {
this._onFinish();
this._players.forEach(player => player.destroy());
this._destroyed = true;
}
}
setPosition(p: any /** TODO #9100 */): void { this._players[0].setPosition(p); }