Skip to content

Commit 5bfafd1

Browse files
authored
fix(dialogs): modal handling (#18)
1 parent 2dca0ce commit 5bfafd1

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
<GridLayout backgroundColor="blue" padding="20" width="100%" height="100%">
2-
<Label [nativeDialogClose]="'thanks for clicking modal ' + id" text="in modal" color="white" fontSize="20"></Label>
1+
<GridLayout backgroundColor="blue" columns="*,*" padding="20" width="100%" height="100%">
2+
<Button col="0" [nativeDialogClose]="'thanks for clicking modal ' + id" text="Close modal" fontSize="20"></Button>
3+
<Button col="1" (tap)="openNewModal()" text="Open new modal" fontSize="20"></Button>
34
</GridLayout>

apps/nativescript-demo-ng/src/app/modal/modal.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { Component, Inject, Optional } from '@angular/core';
2-
import { NativeDialogRef } from '@nativescript/angular';
1+
import { Component, Inject, OnDestroy, OnInit, Optional, ViewContainerRef } from '@angular/core';
2+
import { ModalDialogService, NativeDialogRef, NativeDialogService } from '@nativescript/angular';
33

44
@Component({
55
selector: 'ns-modal',
66
templateUrl: `./modal.component.html`,
77
})
8-
export class ModalComponent {
8+
export class ModalComponent implements OnInit, OnDestroy {
99
id = Math.floor(Math.random() * 1000);
1010

11-
constructor(@Optional() ref: NativeDialogRef<ModalComponent>) {}
11+
constructor(@Optional() private ref: NativeDialogRef<ModalComponent>, private nativeDialog: NativeDialogService, private modalDialog: ModalDialogService, private vcRef: ViewContainerRef) {}
12+
13+
openNewModal() {
14+
this.nativeDialog.open(ModalComponent);
15+
// this.modalDialog.showModal(ModalComponent, {
16+
// viewContainerRef: this.vcRef
17+
// });
18+
}
1219
ngOnInit() {
1320
console.log('modal init');
1421
}

packages/angular/src/lib/legacy/directives/dialogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class ModalDialogService {
140140
ɵmarkDirty(componentRef.instance);
141141
componentViewRef = new NgViewRef(componentRef);
142142
if (componentViewRef !== componentRef.location.nativeElement) {
143-
componentRef.location.nativeElement._ngDialogRoot = componentViewRef;
143+
componentRef.location.nativeElement._ngDialogRoot = componentViewRef.firstNativeLikeView;
144144
}
145145
// if we don't detach the view from its parent, ios gets mad
146146
componentViewRef.detachNativeLikeView();

packages/angular/src/lib/views/utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ export function getFirstNativeLikeView(view: View, extractFromNSParent = false)
2929
}
3030
return getFirstNativeLikeView(view.getChildAt(0));
3131
}
32-
if (isContentView(view)) {
33-
return getFirstNativeLikeView(view.content);
34-
}
3532

3633
if (extractFromNSParent) {
3734
// const node = view.parentNode;

0 commit comments

Comments
 (0)