Skip to content

Commit

Permalink
feat: allow providing custom dialog view (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Jul 17, 2024
1 parent f2b45f6 commit 16bfffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/angular/src/lib/cdk/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Omit<ShowModalOptions, 'cancelable' | 'closeCallback'>>;
/**
Expand All @@ -22,6 +22,9 @@ export class NativeDialogConfig<D = any> {
*/
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;

Expand Down
9 changes: 7 additions & 2 deletions packages/angular/src/lib/cdk/dialog/native-modal-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 16bfffb

Please sign in to comment.