Skip to content

Commit e59d156

Browse files
authored
fix(ios-dialogs): unable to show dialog from modal view without a page (#5881)
* fix(ios-dialogs): unable to show dialog from modal view * tests(modal-navigation): add test that opens dialog inside modal view
1 parent 6d978ad commit e59d156

11 files changed

Lines changed: 90 additions & 16 deletions

File tree

‎e2e/modal-navigation/app/home/home-page.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ export function onNavigatedFrom(args: NavigatedData) {
2020
console.log("home-page onNavigatedFrom");
2121
}
2222

23+
export function onModalNoPage(args: EventData) {
24+
const view = args.object as View;
25+
26+
view.showModal("modal-no-page/modal-no-page",
27+
"context",
28+
() => console.log("home-page modal frame closed"),
29+
false);
30+
}
31+
2332
export function onModalFrame(args: EventData) {
2433
const view = args.object as View;
2534

‎e2e/modal-navigation/app/home/home-page.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</ActionBar>
1111

1212
<StackLayout>
13+
<Button text="Show Modal Without Page" tap="onModalNoPage" />
1314
<Button text="Show Modal Page With Frame" tap="onModalFrame" />
1415
<Button text="Show Modal Page" tap="onModalPage" />
1516
<Button text="Show Modal Layout" tap="onModalLayout" />

‎e2e/modal-navigation/app/layout-root.ios.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {
2+
onModalNoPage,
23
onModalFrame,
34
onModalPage,
45
onModalLayout,

‎e2e/modal-navigation/app/layout-root.ios.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<StackLayout>
22
<Label text="Home" horizontalAlignment="center" />
3+
<Button text="Show Modal Without Page" tap="onModalNoPage" />
34
<Button text="Show Modal Page With Frame" tap="onModalFrame" />
45
<Button text="Show Modal Page" tap="onModalPage" />
56
<Button text="Show Modal Layout" tap="onModalLayout" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
2+
import { NavigatedData, Page } from "tns-core-modules/ui/page";
3+
import { View, EventData } from "tns-core-modules/ui/core/view";
4+
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
5+
import { fromObject } from "tns-core-modules/data/observable";
6+
import { confirm } from "ui/dialogs";
7+
8+
export function onLoaded(args) {
9+
console.log("modal-no-page loaded");
10+
}
11+
12+
export function closeModal(args: EventData) {
13+
(args.object as View).closeModal();
14+
}
15+
16+
export function showDialog(args: EventData) {
17+
let options = {
18+
title: "Dialog",
19+
message: "Message",
20+
okButtonText: "Yes",
21+
cancelButtonText: "No"
22+
23+
}
24+
25+
confirm(options).then((result: boolean) => {
26+
console.log(result);
27+
})
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<StackLayout backgroundColor="lightGreen" loaded="onLoaded">
2+
<Button text="Show Dialog" tap="showDialog"/>
3+
<Button text="Close Modal" tap="closeModal" />
4+
</StackLayout>

‎e2e/modal-navigation/app/modal/modal-page.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page";
33
import { View, EventData } from "tns-core-modules/ui/core/view";
44
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
55
import { fromObject } from "tns-core-modules/data/observable";
6+
import { confirm } from "ui/dialogs";
67

78
export function onShowingModally(args: ShownModallyData) {
89
console.log("modal-page showingModally");
@@ -64,4 +65,18 @@ export function onNavigate(args: EventData) {
6465
const view = args.object as View;
6566
const page = view.page as Page;
6667
page.frame.navigate("modal-second/modal-second-page");
68+
}
69+
70+
export function showDialog(args: EventData) {
71+
let options = {
72+
title: "Dialog",
73+
message: "Message",
74+
okButtonText: "Yes",
75+
cancelButtonText: "No"
76+
77+
}
78+
79+
confirm(options).then((result: boolean) => {
80+
console.log(result);
81+
})
6782
}

‎e2e/modal-navigation/app/modal/modal-page.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<StackLayout backgroundColor="lightGreen">
1212
<Button text="Navigate To Second Page" tap="onNavigate" visibility="{{ navigationVisibility }}" />
13+
<Button text="Show Dialog" tap="showDialog" />
1314
<Button text="Show Nested Modal Page With Frame" tap="showNestedModalFrame" />
1415
<Button text="Show Nested Modal Page" tap="showNestedModalPage" />
1516
<Button text="Close Modal" tap="closeModal" />

‎tns-core-modules/ui/core/view/view.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ export const isEnabledProperty: Property<View, boolean>;
775775
export const isUserInteractionEnabledProperty: Property<View, boolean>;
776776

777777
export namespace ios {
778+
export function getParentWithViewController(parent: View): View
778779
export function isContentScrollable(controller: any /* UIViewController */, owner: View): boolean
779780
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void
780781
export function updateConstraints(controller: any /* UIViewController */, owner: View): void;

‎tns-core-modules/ui/core/view/view.ios.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,8 @@ export class View extends ViewCommon {
308308
return this._suspendCATransaction || this._suspendNativeUpdatesCount;
309309
}
310310

311-
private getParentWithViewController(parent: View): View {
312-
let view = parent;
313-
let controller = view.viewController;
314-
while (!controller) {
315-
view = view.parent as View;
316-
controller = view.viewController;
317-
}
318-
319-
return view;
320-
}
321311
protected _showNativeModalView(parent: View, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean) {
322-
let parentWithController = this.getParentWithViewController(parent);
312+
let parentWithController = ios.getParentWithViewController(parent);
323313

324314
super._showNativeModalView(parentWithController, context, closeCallback, fullscreen, stretched);
325315
let controller = this.viewController;
@@ -592,6 +582,17 @@ export class CustomLayoutView extends View {
592582
}
593583

594584
export namespace ios {
585+
export function getParentWithViewController(parent: View): View {
586+
let view = parent;
587+
let controller = view.viewController;
588+
while (!controller) {
589+
view = view.parent as View;
590+
controller = view.viewController;
591+
}
592+
593+
return view;
594+
}
595+
595596
export function isContentScrollable(controller: UIViewController, owner: View): boolean {
596597
let scrollableContent = (<any>owner).scrollableContent;
597598
if (scrollableContent === undefined) {

0 commit comments

Comments
 (0)