mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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
This commit is contained in:
committed by
GitHub
parent
6d978add18
commit
e59d1567a5
1
tns-core-modules/ui/core/view/view.d.ts
vendored
1
tns-core-modules/ui/core/view/view.d.ts
vendored
@@ -775,6 +775,7 @@ export const isEnabledProperty: Property<View, boolean>;
|
||||
export const isUserInteractionEnabledProperty: Property<View, boolean>;
|
||||
|
||||
export namespace ios {
|
||||
export function getParentWithViewController(parent: View): View
|
||||
export function isContentScrollable(controller: any /* UIViewController */, owner: View): boolean
|
||||
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void
|
||||
export function updateConstraints(controller: any /* UIViewController */, owner: View): void;
|
||||
|
||||
@@ -308,18 +308,8 @@ export class View extends ViewCommon {
|
||||
return this._suspendCATransaction || this._suspendNativeUpdatesCount;
|
||||
}
|
||||
|
||||
private getParentWithViewController(parent: View): View {
|
||||
let view = parent;
|
||||
let controller = view.viewController;
|
||||
while (!controller) {
|
||||
view = view.parent as View;
|
||||
controller = view.viewController;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
protected _showNativeModalView(parent: View, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean) {
|
||||
let parentWithController = this.getParentWithViewController(parent);
|
||||
let parentWithController = ios.getParentWithViewController(parent);
|
||||
|
||||
super._showNativeModalView(parentWithController, context, closeCallback, fullscreen, stretched);
|
||||
let controller = this.viewController;
|
||||
@@ -592,6 +582,17 @@ export class CustomLayoutView extends View {
|
||||
}
|
||||
|
||||
export namespace ios {
|
||||
export function getParentWithViewController(parent: View): View {
|
||||
let view = parent;
|
||||
let controller = view.viewController;
|
||||
while (!controller) {
|
||||
view = view.parent as View;
|
||||
controller = view.viewController;
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
export function isContentScrollable(controller: UIViewController, owner: View): boolean {
|
||||
let scrollableContent = (<any>owner).scrollableContent;
|
||||
if (scrollableContent === undefined) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* iOS specific dialogs functions implementation.
|
||||
*/
|
||||
|
||||
import { View, ios as iosView } from "../core/view";
|
||||
import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from ".";
|
||||
import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common";
|
||||
import { isString, isDefined, isFunction } from "../../utils/types";
|
||||
@@ -42,7 +42,7 @@ export function alert(arg: any): Promise<void> {
|
||||
try {
|
||||
let options = !isDialogOptions(arg) ? { title: ALERT, okButtonText: OK, message: arg + "" } : arg;
|
||||
let alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert);
|
||||
|
||||
|
||||
addButtonsToAlertController(alertController, options, () => { resolve(); });
|
||||
|
||||
showUIAlertController(alertController);
|
||||
@@ -157,7 +157,7 @@ export function login(): Promise<LoginResult> {
|
||||
let alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert);
|
||||
|
||||
let textFieldColor = getTextFieldColor();
|
||||
|
||||
|
||||
alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => {
|
||||
arg.placeholder = "Login";
|
||||
arg.text = isString(options.userName) ? options.userName : "";
|
||||
@@ -185,7 +185,7 @@ export function login(): Promise<LoginResult> {
|
||||
resolve({
|
||||
result: r,
|
||||
userName:
|
||||
userNameTextField.text,
|
||||
userNameTextField.text,
|
||||
password: passwordTextField.text
|
||||
});
|
||||
});
|
||||
@@ -200,7 +200,19 @@ export function login(): Promise<LoginResult> {
|
||||
function showUIAlertController(alertController: UIAlertController) {
|
||||
let currentPage = getCurrentPage();
|
||||
if (currentPage) {
|
||||
let viewController: UIViewController = currentPage.modal ? currentPage.modal.ios : currentPage.ios;
|
||||
let view: View = currentPage;
|
||||
let viewController: UIViewController = currentPage.ios;
|
||||
|
||||
if (currentPage.modal) {
|
||||
view = currentPage.modal;
|
||||
|
||||
if (view.ios instanceof UIViewController) {
|
||||
viewController = view.ios;
|
||||
} else {
|
||||
viewController = iosView.getParentWithViewController(view).viewController;
|
||||
}
|
||||
}
|
||||
|
||||
if (viewController) {
|
||||
if (alertController.popoverPresentationController) {
|
||||
alertController.popoverPresentationController.sourceView = viewController.view;
|
||||
|
||||
Reference in New Issue
Block a user