FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ios-dialogs): unable to show dialog from modal view without a page by ADjenkov · Pull Request #5881 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (7) .xml  (4) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 9 additions & 0 deletions e2e/modal-navigation/app/home/home-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export function onNavigatedFrom(args: NavigatedData) {
console.log("home-page onNavigatedFrom");
}

export function onModalNoPage(args: EventData) {
const view = args.object as View;

view.showModal("modal-no-page/modal-no-page",
"context",
() => console.log("home-page modal frame closed"),
false);
}

export function onModalFrame(args: EventData) {
const view = args.object as View;

Expand Down
1 change: 1 addition & 0 deletions e2e/modal-navigation/app/home/home-page.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ActionBar>

<StackLayout>
<Button text="Show Modal Without Page" tap="onModalNoPage" />
<Button text="Show Modal Page With Frame" tap="onModalFrame" />
<Button text="Show Modal Page" tap="onModalPage" />
<Button text="Show Modal Layout" tap="onModalLayout" />
Expand Down
1 change: 1 addition & 0 deletions e2e/modal-navigation/app/layout-root.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
onModalNoPage,
onModalFrame,
onModalPage,
onModalLayout,
Expand Down
1 change: 1 addition & 0 deletions e2e/modal-navigation/app/layout-root.ios.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<StackLayout>
<Label text="Home" horizontalAlignment="center" />
<Button text="Show Modal Without Page" tap="onModalNoPage" />
<Button text="Show Modal Page With Frame" tap="onModalFrame" />
<Button text="Show Modal Page" tap="onModalPage" />
<Button text="Show Modal Layout" tap="onModalLayout" />
Expand Down
28 changes: 28 additions & 0 deletions e2e/modal-navigation/app/modal-no-page/modal-no-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { NavigatedData, Page } from "tns-core-modules/ui/page";
import { View, EventData } from "tns-core-modules/ui/core/view";
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
import { fromObject } from "tns-core-modules/data/observable";
import { confirm } from "ui/dialogs";

export function onLoaded(args) {
console.log("modal-no-page loaded");
}

export function closeModal(args: EventData) {
(args.object as View).closeModal();
}

export function showDialog(args: EventData) {
let options = {
title: "Dialog",
message: "Message",
okButtonText: "Yes",
cancelButtonText: "No"

}

confirm(options).then((result: boolean) => {
console.log(result);
})
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<StackLayout backgroundColor="lightGreen" loaded="onLoaded">
<Button text="Show Dialog" tap="showDialog"/>
<Button text="Close Modal" tap="closeModal" />
</StackLayout>
15 changes: 15 additions & 0 deletions e2e/modal-navigation/app/modal/modal-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page";
import { View, EventData } from "tns-core-modules/ui/core/view";
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
import { fromObject } from "tns-core-modules/data/observable";
import { confirm } from "ui/dialogs";

export function onShowingModally(args: ShownModallyData) {
console.log("modal-page showingModally");
Expand Down Expand Up @@ -64,4 +65,18 @@ export function onNavigate(args: EventData) {
const view = args.object as View;
const page = view.page as Page;
page.frame.navigate("modal-second/modal-second-page");
}

export function showDialog(args: EventData) {
let options = {
title: "Dialog",
message: "Message",
okButtonText: "Yes",
cancelButtonText: "No"

}

confirm(options).then((result: boolean) => {
console.log(result);
})
}
1 change: 1 addition & 0 deletions e2e/modal-navigation/app/modal/modal-page.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<StackLayout backgroundColor="lightGreen">
<Button text="Navigate To Second Page" tap="onNavigate" visibility="{{ navigationVisibility }}" />
<Button text="Show Dialog" tap="showDialog" />
<Button text="Show Nested Modal Page With Frame" tap="showNestedModalFrame" />
<Button text="Show Nested Modal Page" tap="showNestedModalPage" />
<Button text="Close Modal" tap="closeModal" />
Expand Down
1 change: 1 addition & 0 deletions tns-core-modules/ui/core/view/view.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions tns-core-modules/ui/core/view/view.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 17 additions & 5 deletions tns-core-modules/ui/dialogs/dialogs.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 : "";
Expand Down Expand Up @@ -185,7 +185,7 @@ export function login(): Promise<LoginResult> {
resolve({
result: r,
userName:
userNameTextField.text,
userNameTextField.text,
password: passwordTextField.text
});
});
Expand All @@ -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;
Expand Down

Back | FazBrowse Home | New Git URL