Skip to content

Commit 5ddcd6c

Browse files
committed
MOBILE-2314 core: Fix custom modals lifecycle
1 parent 579057d commit 5ddcd6c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/core/components/sheet-modal/sheet-modal.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
3434

3535
private element: HTMLElement;
3636
private wrapperElement = new CorePromisedValue<HTMLElement>();
37+
private content?: HTMLElement;
3738

3839
constructor({ nativeElement: element }: ElementRef<HTMLElement>) {
3940
this.element = element;
@@ -61,7 +62,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
6162
*/
6263
async show(): Promise<T> {
6364
const wrapper = await this.wrapperElement;
64-
const element = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {});
65+
this.content = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {});
6566

6667
await CoreUtils.nextTick();
6768

@@ -71,7 +72,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
7172
await CoreUtils.nextTick();
7273
await CoreUtils.wait(300);
7374

74-
const instance = CoreDirectivesRegistry.resolve(element, this.component);
75+
const instance = CoreDirectivesRegistry.resolve(this.content, this.component);
7576

7677
if (!instance) {
7778
throw new Error('Modal not mounted properly');
@@ -84,10 +85,13 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
8485
* Hide modal.
8586
*/
8687
async hide(): Promise<void> {
88+
const wrapper = await this.wrapperElement;
89+
8790
this.element.classList.remove('active');
8891

8992
await CoreUtils.nextTick();
9093
await CoreUtils.wait(300);
94+
await AngularFrameworkDelegate.removeViewFromDom(wrapper, this.content);
9195
}
9296

9397
}

src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ export class CoreFileUploaderAudioRecorderComponent extends CoreModalComponent<C
8686
* @inheritdoc
8787
*/
8888
ngOnDestroy(): void {
89-
this.media$.value?.recorder.stop();
89+
const recorder = this.media$.value?.recorder;
90+
91+
if (recorder && recorder.state !== 'inactive') {
92+
recorder.stop();
93+
}
9094
}
9195

9296
/**

src/core/services/modals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class CoreModalsService {
7676

7777
modal.result.finally(async () => {
7878
await sheetModal.hide();
79+
await AngularFrameworkDelegate.removeViewFromDom(container, element);
7980

80-
element.remove();
8181
viewContainer?.removeAttribute('aria-hidden');
8282
});
8383

0 commit comments

Comments
 (0)