From 7f1f9fcb91b9141261d8455527cb9441e322e257 Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Thu, 30 Nov 2023 09:11:51 -0300 Subject: [PATCH] feat: allow providing custom dialog view --- packages/angular/src/lib/cdk/dialog/dialog-config.ts | 5 ++++- packages/angular/src/lib/cdk/dialog/native-modal-ref.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/angular/src/lib/cdk/dialog/dialog-config.ts b/packages/angular/src/lib/cdk/dialog/dialog-config.ts index 6fbaf5c..44c7117 100644 --- a/packages/angular/src/lib/cdk/dialog/dialog-config.ts +++ b/packages/angular/src/lib/cdk/dialog/dialog-config.ts @@ -7,7 +7,7 @@ */ import { ViewContainerRef, ComponentFactoryResolver } from '@angular/core'; -import { ShowModalOptions } from '@nativescript/core'; +import { ShowModalOptions, View } from '@nativescript/core'; export type NativeShowModalOptions = Partial>; /** @@ -22,6 +22,9 @@ export class NativeDialogConfig { */ viewContainerRef?: ViewContainerRef; + /** Where to render the actual dialog in. By default it renders using the native view of the ViewContainerRef */ + renderIn: 'root' | 'viewContainerRef' | View = 'viewContainerRef'; + /** ID for the dialog. If omitted, a unique one will be generated. */ id?: string; diff --git a/packages/angular/src/lib/cdk/dialog/native-modal-ref.ts b/packages/angular/src/lib/cdk/dialog/native-modal-ref.ts index 3e7104f..01748f6 100644 --- a/packages/angular/src/lib/cdk/dialog/native-modal-ref.ts +++ b/packages/angular/src/lib/cdk/dialog/native-modal-ref.ts @@ -24,8 +24,13 @@ export class NativeModalRef { private _closeCallback: () => void; private _isDismissed = false; - constructor(private _config: NativeDialogConfig, private _injector: Injector, @Optional() private location?: NSLocationStrategy) { - let parentView = this._config.viewContainerRef?.element.nativeElement || Application.getRootView(); + constructor( + private _config: NativeDialogConfig, + private _injector: Injector, + @Optional() private location?: NSLocationStrategy, + ) { + const nativeElement = this._config.renderIn === 'root' ? Application.getRootView() : this._config.renderIn === 'viewContainerRef' ? this._config.viewContainerRef?.element.nativeElement : this._config.renderIn; + let parentView = nativeElement || Application.getRootView(); if ((parentView instanceof AppHostView || parentView instanceof AppHostAsyncView) && parentView.ngAppRoot) { parentView = parentView.ngAppRoot;