Skip to content

Commit 7c8424b

Browse files
author
Marcus Williams
committed
add popover
1 parent d67f199 commit 7c8424b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Diff for: nativescript-angular/directives/dialogs.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ReflectiveInjector,
88
Type,
99
ViewContainerRef,
10+
ElementRef,
1011
} from "@angular/core";
1112

1213
import { NSLocationStrategy } from "../router/ns-location-strategy";
@@ -26,6 +27,8 @@ export interface ModalDialogOptions {
2627
stretched?: boolean;
2728
viewContainerRef?: ViewContainerRef;
2829
moduleRef?: NgModuleRef<any>;
30+
sourceView?: ElementRef;
31+
ios?: any;
2932
}
3033

3134
export class ModalDialogParams {
@@ -46,15 +49,17 @@ interface ShowDialogOptions {
4649
parentView: ViewBase;
4750
resolver: ComponentFactoryResolver;
4851
type: Type<any>;
52+
ios?: any;
4953
}
5054

5155
@Injectable()
5256
export class ModalDialogService {
57+
private componentView: View;
5358
constructor(private location: NSLocationStrategy) {
5459
}
5560

5661
public showModal(type: Type<any>,
57-
{ viewContainerRef, moduleRef, context, fullscreen, animated, stretched }: ModalDialogOptions
62+
{ viewContainerRef, moduleRef, context, fullscreen, animated, stretched, sourceView, ios }: ModalDialogOptions
5863
): Promise<any> {
5964
if (!viewContainerRef) {
6065
throw new Error(
@@ -63,7 +68,11 @@ export class ModalDialogService {
6368
);
6469
}
6570

66-
let parentView = viewContainerRef.element.nativeElement;
71+
if (sourceView) {
72+
this.closeModal();
73+
}
74+
75+
let parentView = sourceView ? sourceView.nativeElement : viewContainerRef.element.nativeElement;
6776
if (parentView instanceof AppHostView && parentView.ngAppRoot) {
6877
parentView = parentView.ngAppRoot;
6978
}
@@ -105,6 +114,7 @@ export class ModalDialogService {
105114
parentView,
106115
resolver,
107116
type,
117+
ios
108118
});
109119
} catch (err) {
110120
reject(err);
@@ -113,6 +123,13 @@ export class ModalDialogService {
113123
});
114124
}
115125

126+
public closeModal() {
127+
if (this.componentView) {
128+
this.componentView.closeModal();
129+
this.location._closeModalNavigation();
130+
}
131+
}
132+
116133
private _showDialog({
117134
containerRef,
118135
context,
@@ -124,6 +141,7 @@ export class ModalDialogService {
124141
parentView,
125142
resolver,
126143
type,
144+
ios
127145
}: ShowDialogOptions): void {
128146
let componentView: View;
129147
let detachedLoaderRef: ComponentRef<DetachedLoader>;
@@ -161,7 +179,12 @@ export class ModalDialogService {
161179

162180
// TODO: remove <any> cast after https://github.com/NativeScript/NativeScript/pull/5734
163181
// is in a published version of tns-core-modules.
164-
(<any>parentView).showModal(componentView, context, closeCallback, fullscreen, animated, stretched);
182+
if (ios) {
183+
(<any>parentView).showModal(componentView, { context, closeCallback, fullscreen, animated, stretched, ios });
184+
} else {
185+
(<any>parentView).showModal(componentView, context, closeCallback, fullscreen, animated, stretched);
186+
}
187+
this.componentView = componentView;
165188
});
166189
}
167190
}

0 commit comments

Comments
 (0)