Skip to content

fix(dialogs): unable to show nested frameless modal views #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/modal-navigation-ng/app/modal/modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<StackLayout backgroundColor="lightGreen">
<Button text="Navigate To Second Page" (tap)="onNavigateSecondPage()" [visibility]="navigationVisibility"></Button>
<Button text="Show Nested Modal Page With Frame" (tap)="showNestedModalFrame()" [visibility]="navigationVisibility"></Button>
<Button text="Show Nested Modal Page" (tap)="showNestedModal()" [visibility]="navigationVisibility"></Button>
<Button text="Show Nested Modal Page" (tap)="showNestedModal()"></Button>
<Button text="Show Dialog" (tap)="showDialogConfirm()"></Button>
<Button text="Close Modal" (tap)="close(rootLayout)"></Button>
</StackLayout>
Expand Down
4 changes: 4 additions & 0 deletions e2e/modal-navigation-ng/e2e/modal-layout.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
12 changes: 11 additions & 1 deletion nativescript-angular/directives/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ 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;
}

const pageFactory: PageFactory = viewContainerRef.injector.get(PAGE_FACTORY);

// resolve from particular module (moduleRef)
Expand All @@ -76,7 +83,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(() => {
Expand Down Expand Up @@ -144,6 +153,7 @@ export class ModalDialogService {
componentView = detachedProxy.getChildAt(0);

if (componentView.parent) {
(<any>componentView.parent)._ngDialogRoot = componentView;
(<any>componentView.parent).removeChild(componentView);
}

Expand Down
9 changes: 7 additions & 2 deletions tests/app/tests/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FakeFrame extends View implements Frame {
}
}

navigate(entry: any) {}
navigate(entry: any) { }

constructor(private backCB?: () => void) {
super();
Expand Down Expand Up @@ -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 {
Expand Down