diff --git a/e2e/ui-tests-app/app/modal-view/login-page.ts b/e2e/ui-tests-app/app/modal-view/login-page.ts
index 3781b4538..35c326a50 100644
--- a/e2e/ui-tests-app/app/modal-view/login-page.ts
+++ b/e2e/ui-tests-app/app/modal-view/login-page.ts
@@ -1,5 +1,6 @@
import { Page, ShownModallyData } from "tns-core-modules/ui/page";
import { EventData, fromObject } from "tns-core-modules/data/observable";
+import { alert } from "tns-core-modules/ui/dialogs";
export function onShowingModally(args: ShownModallyData) {
console.log("login-page.onShowingModally, context: " + args.context);
@@ -12,7 +13,19 @@ export function onShowingModally(args: ShownModallyData) {
onLoginButtonTap: function () {
console.log("login-page.onLoginButtonTap");
args.closeCallback(this.username, this.password);
- }
+ },
+ showAlert: function () {
+ alert("showing alert!");
+ args.closeCallback();
+ },
+ openNestedModal: function () {
+ page.showModal("modal-view/nested-modal", {
+ context: "First",
+ closeCallback: () => {
+ console.log("login-page.openNestedModal");
+ }
+ });
+ }
});
}
diff --git a/e2e/ui-tests-app/app/modal-view/login-page.xml b/e2e/ui-tests-app/app/modal-view/login-page.xml
index 4605aa14f..f0208a2c4 100644
--- a/e2e/ui-tests-app/app/modal-view/login-page.xml
+++ b/e2e/ui-tests-app/app/modal-view/login-page.xml
@@ -7,5 +7,7 @@
+
+
diff --git a/e2e/ui-tests-app/app/modal-view/nested-modal.ts b/e2e/ui-tests-app/app/modal-view/nested-modal.ts
new file mode 100644
index 000000000..b438ad2a2
--- /dev/null
+++ b/e2e/ui-tests-app/app/modal-view/nested-modal.ts
@@ -0,0 +1,27 @@
+import { Page, ShownModallyData } from "tns-core-modules/ui/page";
+import { EventData, fromObject } from "tns-core-modules/data/observable";
+import { alert } from "tns-core-modules/ui/dialogs";
+
+export function onShowingModally(args: ShownModallyData) {
+ console.log("nested-modal.onShowingModally, context: " + args.context);
+ const page = args.object;
+
+ page.bindingContext = fromObject({
+ context: args.context,
+ onTap: function () {
+ alert("it works!");
+ }
+ });
+}
+
+export function onShownModally(args: ShownModallyData) {
+ console.log("nested-modal.onShownModally, context: " + args.context);
+}
+
+export function onLoaded(args: EventData) {
+ console.log("nested-modal.onLoaded");
+}
+
+export function onUnloaded() {
+ console.log("nested-modal.onUnloaded");
+}
diff --git a/e2e/ui-tests-app/app/modal-view/nested-modal.xml b/e2e/ui-tests-app/app/modal-view/nested-modal.xml
new file mode 100644
index 000000000..7795a0afa
--- /dev/null
+++ b/e2e/ui-tests-app/app/modal-view/nested-modal.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
diff --git a/nativescript-core/ui/dialogs/dialogs.ios.ts b/nativescript-core/ui/dialogs/dialogs.ios.ts
index f7eb1dbe6..0e172c607 100644
--- a/nativescript-core/ui/dialogs/dialogs.ios.ts
+++ b/nativescript-core/ui/dialogs/dialogs.ios.ts
@@ -1,11 +1,11 @@
/**
* iOS specific dialogs functions implementation.
*/
-import { ios as iosView } from "../core/view";
+import { ios as iosView, traceCategories, traceWrite, traceMessageType } from "../core/view";
import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from ".";
import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, capitalizationType, ALERT, OK, CONFIRM, CANCEL, PROMPT, parseLoginOptions } from "./dialogs-common";
import { isString, isDefined, isFunction } from "../../utils/types";
-import { getRootView } from "../../application";
+import { getRootView, ios } from "../../application";
export * from "./dialogs-common";
@@ -200,54 +200,42 @@ export function login(...args: any[]): Promise {
}
function showUIAlertController(alertController: UIAlertController) {
- let currentView = getCurrentPage() || getRootView();
+ let viewController = ios.rootController;
+
+ while (viewController && viewController.presentedViewController) {
+ viewController = viewController.presentedViewController;
+ }
- if (currentView) {
- currentView = currentView.modal || currentView;
+ if (!viewController) {
+ traceWrite(`No root controller found to open dialog.`, traceCategories.Error, traceMessageType.warn);
+
+ return;
+ }
- //get to the top most view controller on the stack
- while (currentView && currentView.modal) {
- currentView = currentView.modal;
+ if (alertController.popoverPresentationController) {
+ alertController.popoverPresentationController.sourceView = viewController.view;
+ alertController.popoverPresentationController.sourceRect = CGRectMake(viewController.view.bounds.size.width / 2.0, viewController.view.bounds.size.height / 2.0, 1.0, 1.0);
+ alertController.popoverPresentationController.permittedArrowDirections = 0;
+ }
+
+ let color = getButtonColors().color;
+ if (color) {
+ alertController.view.tintColor = color.ios;
+ }
+
+ let lblColor = getLabelColor();
+ if (lblColor) {
+ if (alertController.title) {
+ let title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, { [NSForegroundColorAttributeName]: lblColor.ios });
+ alertController.setValueForKey(title, "attributedTitle");
}
-
- let viewController: UIViewController = currentView.ios;
-
- if (viewController.presentedViewController) {
- viewController = viewController.presentedViewController;
- }
-
- if (!(currentView.ios instanceof UIViewController)) {
- const parentWithController = iosView.getParentWithViewController(currentView);
- viewController = parentWithController ? parentWithController.viewController : undefined;
- }
-
- if (viewController) {
- if (alertController.popoverPresentationController) {
- alertController.popoverPresentationController.sourceView = viewController.view;
- alertController.popoverPresentationController.sourceRect = CGRectMake(viewController.view.bounds.size.width / 2.0, viewController.view.bounds.size.height / 2.0, 1.0, 1.0);
- alertController.popoverPresentationController.permittedArrowDirections = 0;
- }
-
- let color = getButtonColors().color;
- if (color) {
- alertController.view.tintColor = color.ios;
- }
-
- let lblColor = getLabelColor();
- if (lblColor) {
- if (alertController.title) {
- let title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, { [NSForegroundColorAttributeName]: lblColor.ios });
- alertController.setValueForKey(title, "attributedTitle");
- }
- if (alertController.message) {
- let message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, { [NSForegroundColorAttributeName]: lblColor.ios });
- alertController.setValueForKey(message, "attributedMessage");
- }
- }
-
- viewController.presentModalViewControllerAnimated(alertController, true);
+ if (alertController.message) {
+ let message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, { [NSForegroundColorAttributeName]: lblColor.ios });
+ alertController.setValueForKey(message, "attributedMessage");
}
}
+
+ viewController.presentModalViewControllerAnimated(alertController, true);
}
export function action(): Promise {