MOBILE-2314 core: Fix custom modals lifecycle

main
Noel De Martin 2023-02-23 13:50:15 +01:00
parent 579057ddf8
commit 5ddcd6cfc4
3 changed files with 12 additions and 4 deletions

View File

@ -34,6 +34,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
private element: HTMLElement; private element: HTMLElement;
private wrapperElement = new CorePromisedValue<HTMLElement>(); private wrapperElement = new CorePromisedValue<HTMLElement>();
private content?: HTMLElement;
constructor({ nativeElement: element }: ElementRef<HTMLElement>) { constructor({ nativeElement: element }: ElementRef<HTMLElement>) {
this.element = element; this.element = element;
@ -61,7 +62,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
*/ */
async show(): Promise<T> { async show(): Promise<T> {
const wrapper = await this.wrapperElement; const wrapper = await this.wrapperElement;
const element = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {}); this.content = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {});
await CoreUtils.nextTick(); await CoreUtils.nextTick();
@ -71,7 +72,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
await CoreUtils.nextTick(); await CoreUtils.nextTick();
await CoreUtils.wait(300); await CoreUtils.wait(300);
const instance = CoreDirectivesRegistry.resolve(element, this.component); const instance = CoreDirectivesRegistry.resolve(this.content, this.component);
if (!instance) { if (!instance) {
throw new Error('Modal not mounted properly'); throw new Error('Modal not mounted properly');
@ -84,10 +85,13 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
* Hide modal. * Hide modal.
*/ */
async hide(): Promise<void> { async hide(): Promise<void> {
const wrapper = await this.wrapperElement;
this.element.classList.remove('active'); this.element.classList.remove('active');
await CoreUtils.nextTick(); await CoreUtils.nextTick();
await CoreUtils.wait(300); await CoreUtils.wait(300);
await AngularFrameworkDelegate.removeViewFromDom(wrapper, this.content);
} }
} }

View File

@ -86,7 +86,11 @@ export class CoreFileUploaderAudioRecorderComponent extends CoreModalComponent<C
* @inheritdoc * @inheritdoc
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.media$.value?.recorder.stop(); const recorder = this.media$.value?.recorder;
if (recorder && recorder.state !== 'inactive') {
recorder.stop();
}
} }
/** /**

View File

@ -76,8 +76,8 @@ export class CoreModalsService {
modal.result.finally(async () => { modal.result.finally(async () => {
await sheetModal.hide(); await sheetModal.hide();
await AngularFrameworkDelegate.removeViewFromDom(container, element);
element.remove();
viewContainer?.removeAttribute('aria-hidden'); viewContainer?.removeAttribute('aria-hidden');
}); });