Close at various times, depending on the animation

This commit is contained in:
Martin 2023-01-30 14:25:43 +01:00
parent 474efe787e
commit 8ce3edb6a9

View File

@ -12,16 +12,19 @@ export abstract class ModalWindow<TParam, TResult> extends Component {
private result: TResult; private result: TResult;
private isDismissed = false; private isDismissed = false;
private openAnimationName = "open";
private closeAnimationName = "close";
public async runAsync(params?: TParam): Promise<TResult> { public async runAsync(params?: TParam): Promise<TResult> {
this.closeButton?.InteractedEvent.on(() => this.dismiss(), this); this.closeButton?.InteractedEvent.on(() => this.dismiss(), this);
this.backgroundCloseButton?.InteractedEvent.on(() => this.dismiss(), this); this.backgroundCloseButton?.InteractedEvent.on(() => this.dismiss(), this);
this.setup(params); this.setup(params);
this.animation?.play("open"); this.animation?.play(this.openAnimationName);
while (!this.isDismissed) await delay(100); while (!this.isDismissed) await delay(100);
this.animation?.play("close"); this.animation?.play(this.closeAnimationName);
await delay(500); await delay(this.getCloseAnimationTime() * 1000);
return this.result; return this.result;
} }
@ -31,4 +34,13 @@ export abstract class ModalWindow<TParam, TResult> extends Component {
this.result = result; this.result = result;
this.isDismissed = true; this.isDismissed = true;
} }
private getCloseAnimationTime(): number {
const state = this.animation?.getState(this.closeAnimationName);
if (state != null) {
return state.duration;
}
return 0;
}
} }