Skip to content

Commit 6155f02

Browse files
authored
fix(dialogs): unable to show nested frameless modal views (#1469)
* fix(dialogs): unable to show nested frameless modal views * chore(modal-navigation-ng): add tests for nested modal views without frames
1 parent eb1a7f0 commit 6155f02

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Diff for: e2e/modal-navigation-ng/app/modal/modal.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<StackLayout backgroundColor="lightGreen">
77
<Button text="Navigate To Second Page" (tap)="onNavigateSecondPage()" [visibility]="navigationVisibility"></Button>
88
<Button text="Show Nested Modal Page With Frame" (tap)="showNestedModalFrame()" [visibility]="navigationVisibility"></Button>
9-
<Button text="Show Nested Modal Page" (tap)="showNestedModal()" [visibility]="navigationVisibility"></Button>
9+
<Button text="Show Nested Modal Page" (tap)="showNestedModal()"></Button>
1010
<Button text="Show Dialog" (tap)="showDialogConfirm()"></Button>
1111
<Button text="Close Modal" (tap)="close(rootLayout)"></Button>
1212
</StackLayout>

Diff for: e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ describe("modal-layout:", () => {
4545
await screen.loadedHome();
4646
});
4747

48+
it("should show nested modal page, run in background, close", async () => {
49+
await testNestedModalPageBackground(driver, screen, false);
50+
});
51+
4852
it("should show dialog confirm inside modal view with no frame, run in background", async () => {
4953
await testDialogBackground(driver, screen, false);
5054
});

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export class ModalDialogService {
6767
parentView = parentView.ngAppRoot;
6868
}
6969

70+
// _ngDialogRoot is the first child of the previously detached proxy.
71+
// It should have 'viewController' (iOS) or '_dialogFragment' (Android) available for
72+
// presenting future modal views.
73+
if (parentView._ngDialogRoot) {
74+
parentView = parentView._ngDialogRoot;
75+
}
76+
7077
const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY);
7178

7279
// resolve from particular module (moduleRef)
@@ -76,7 +83,9 @@ export class ModalDialogService {
7683

7784
const frame = parentView.page && parentView.page.frame;
7885

79-
this.location._beginModalNavigation(frame);
86+
if (frame) {
87+
this.location._beginModalNavigation(frame);
88+
}
8089

8190
return new Promise((resolve, reject) => {
8291
setTimeout(() => {
@@ -144,6 +153,7 @@ export class ModalDialogService {
144153
componentView = detachedProxy.getChildAt(0);
145154

146155
if (componentView.parent) {
156+
(<any>componentView.parent)._ngDialogRoot = componentView;
147157
(<any>componentView.parent).removeChild(componentView);
148158
}
149159

Diff for: tests/app/tests/ns-location-strategy.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class FakeFrame extends View implements Frame {
3636
}
3737
}
3838

39-
navigate(entry: any) {}
39+
navigate(entry: any) { }
4040

4141
constructor(private backCB?: () => void) {
4242
super();
@@ -70,10 +70,15 @@ export class FakeFrame extends View implements Frame {
7070
_findEntryForTag(fragmentTag: string): BackstackEntry {
7171
throw new Error("I am a FakeFrame");
7272
}
73-
7473
_updateBackstack(entry: BackstackEntry, isBack: boolean): void {
7574
throw new Error("I am a FakeFrame");
7675
}
76+
_pushInFrameStack() {
77+
throw new Error("I am a FakeFrame");
78+
}
79+
_removeFromFrameStack() {
80+
throw new Error("I am a FakeFrame");
81+
}
7782
}
7883

7984
function initStrategy(initUrl: string, back?: () => void): NSLocationStrategy {

0 commit comments

Comments
 (0)