From 5f776395546fe5a318aea430f5aee68f450d6ca0 Mon Sep 17 00:00:00 2001 From: ADjenkov Date: Tue, 31 Jul 2018 18:16:15 +0300 Subject: [PATCH 1/2] fix(dialogs): unable to show nested frameless modal views --- nativescript-angular/directives/dialogs.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nativescript-angular/directives/dialogs.ts b/nativescript-angular/directives/dialogs.ts index 961ca362b..143809c23 100644 --- a/nativescript-angular/directives/dialogs.ts +++ b/nativescript-angular/directives/dialogs.ts @@ -67,6 +67,10 @@ export class ModalDialogService { parentView = parentView.ngAppRoot; } + if (parentView._ngDialogRoot) { + parentView = parentView._ngDialogRoot; + } + const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY); // resolve from particular module (moduleRef) @@ -76,7 +80,9 @@ export class ModalDialogService { const frame = parentView.page && parentView.page.frame; - this.location._beginModalNavigation(frame); + if (frame) { + this.location._beginModalNavigation(frame); + } return new Promise((resolve, reject) => { setTimeout(() => { @@ -144,6 +150,7 @@ export class ModalDialogService { componentView = detachedProxy.getChildAt(0); if (componentView.parent) { + (componentView.parent)._ngDialogRoot = componentView; (componentView.parent).removeChild(componentView); } From 4be8f16b2910dd7ea789cf67eaa2f484c344a898 Mon Sep 17 00:00:00 2001 From: ADjenkov Date: Tue, 31 Jul 2018 18:16:58 +0300 Subject: [PATCH 2/2] chore(modal-navigation-ng): add tests for nested modal views without frames --- e2e/modal-navigation-ng/app/modal/modal.component.html | 2 +- e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts | 4 ++++ nativescript-angular/directives/dialogs.ts | 3 +++ tests/app/tests/ns-location-strategy.ts | 9 +++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/e2e/modal-navigation-ng/app/modal/modal.component.html b/e2e/modal-navigation-ng/app/modal/modal.component.html index 342c2cc03..2077becc8 100644 --- a/e2e/modal-navigation-ng/app/modal/modal.component.html +++ b/e2e/modal-navigation-ng/app/modal/modal.component.html @@ -6,7 +6,7 @@ - + diff --git a/e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts b/e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts index 9cd95bea6..945cc4431 100644 --- a/e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts +++ b/e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts @@ -45,6 +45,10 @@ describe("modal-layout:", () => { await screen.loadedHome(); }); + it("should show nested modal page, run in background, close", async () => { + await testNestedModalPageBackground(driver, screen, false); + }); + it("should show dialog confirm inside modal view with no frame, run in background", async () => { await testDialogBackground(driver, screen, false); }); diff --git a/nativescript-angular/directives/dialogs.ts b/nativescript-angular/directives/dialogs.ts index 143809c23..4fc954c96 100644 --- a/nativescript-angular/directives/dialogs.ts +++ b/nativescript-angular/directives/dialogs.ts @@ -67,6 +67,9 @@ export class ModalDialogService { parentView = parentView.ngAppRoot; } + // _ngDialogRoot is the first child of the previously detached proxy. + // It should have 'viewController' (iOS) or '_dialogFragment' (Android) available for + // presenting future modal views. if (parentView._ngDialogRoot) { parentView = parentView._ngDialogRoot; } diff --git a/tests/app/tests/ns-location-strategy.ts b/tests/app/tests/ns-location-strategy.ts index 01824f0ec..e85ff327a 100644 --- a/tests/app/tests/ns-location-strategy.ts +++ b/tests/app/tests/ns-location-strategy.ts @@ -36,7 +36,7 @@ export class FakeFrame extends View implements Frame { } } - navigate(entry: any) {} + navigate(entry: any) { } constructor(private backCB?: () => void) { super(); @@ -70,10 +70,15 @@ export class FakeFrame extends View implements Frame { _findEntryForTag(fragmentTag: string): BackstackEntry { throw new Error("I am a FakeFrame"); } - _updateBackstack(entry: BackstackEntry, isBack: boolean): void { throw new Error("I am a FakeFrame"); } + _pushInFrameStack() { + throw new Error("I am a FakeFrame"); + } + _removeFromFrameStack() { + throw new Error("I am a FakeFrame"); + } } function initStrategy(initUrl: string, back?: () => void): NSLocationStrategy {