| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,32 +1,29 @@ | |||
| 1 | - import * as pages from "tns-core-modules/ui/page"; | ||
| 2 | - import * as textField from "tns-core-modules/ui/text-field"; | ||
| 3 | - import * as observable from "tns-core-modules/data/observable"; | ||
| 1 | + import { Page, ShownModallyData } from "tns-core-modules/ui/page"; | ||
| 2 | + import { EventData, fromObject } from "tns-core-modules/data/observable"; | ||
| 4 | 3 | ||
| 5 | - var context: any; | ||
| 6 | - var closeCallback: Function; | ||
| 4 | + export function onShowingModally(args: ShownModallyData) { | ||
| 5 | + console.log("login-page.onShowingModally, context: " + args.context); | ||
| 6 | + const page = <Page>args.object; | ||
| 7 | 7 | ||
| 8 | - var page: pages.Page; | ||
| 9 | - var usernameTextField: textField.TextField; | ||
| 10 | - var passwordTextField: textField.TextField; | ||
| 8 | + page.bindingContext = fromObject({ | ||
| 9 | + username: "username", | ||
| 10 | + password: "password", | ||
| 11 | + context: args.context, | ||
| 12 | + onLoginButtonTap: function() { | ||
| 13 | + console.log("login-page.onLoginButtonTap"); | ||
| 14 | + args.closeCallback(this.username, this.password); | ||
| 15 | + } | ||
| 16 | + }) | ||
| 17 | + } | ||
| 11 | 18 | ||
| 12 | - export function onShownModally(args: pages.ShownModallyData) { | ||
| 19 | + export function onShownModally(args: ShownModallyData) { | ||
| 13 | 20 | console.log("login-page.onShownModally, context: " + args.context); | |
| 14 | - context = args.context; | ||
| 15 | - closeCallback = args.closeCallback; | ||
| 16 | 21 | } | |
| 17 | 22 | ||
| 18 | - export function onLoaded(args: observable.EventData) { | ||
| 23 | + export function onLoaded(args: EventData) { | ||
| 19 | 24 | console.log("login-page.onLoaded"); | |
| 20 | - page = <pages.Page>args.object; | ||
| 21 | - usernameTextField = page.getViewById<textField.TextField>("username"); | ||
| 22 | - passwordTextField = page.getViewById<textField.TextField>("password"); | ||
| 23 | 25 | } | |
| 24 | 26 | ||
| 25 | 27 | export function onUnloaded() { | |
| 26 | 28 | console.log("login-page.onUnloaded"); | |
| 27 | 29 | } | |
| 28 | - | ||
| 29 | - export function onLoginButtonTap() { | ||
| 30 | - console.log("login-page.onLoginButtonTap"); | ||
| 31 | - closeCallback(usernameTextField.text, passwordTextField.text); | ||
| 32 | - } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,11 @@ | |||
| 1 | - <Page xmlns="http://schemas.nativescript.org/tns.xsd" shownModally="onShownModally" | ||
| 1 | + <Page xmlns="http://schemas.nativescript.org/tns.xsd" | ||
| 2 | + showingModally="onShowingModally" | ||
| 3 | + shownModally="onShownModally" | ||
| 2 | 4 | loaded="onLoaded" unloaded="onUnloaded" backgroundColor="Red"> | |
| 3 | 5 | <StackLayout backgroundColor="PaleGreen" margin="10"> | |
| 4 | - <TextField hint="username" id="username" text="username"/> | ||
| 5 | - <TextField hint="password" id="password" text="password" secure="true"/> | ||
| 6 | - <Button text="Login" tap="onLoginButtonTap"/> | ||
| 6 | + <Label text="{{ context }}"/> | ||
| 7 | + <TextField hint="username" text="{{ username }}"/> | ||
| 8 | + <TextField hint="password" text="{{ password }}" secure="true"/> | ||
| 9 | + <Button text="Login" tap="{{ onLoginButtonTap }}"/> | ||
| 7 | 10 | </StackLayout> | |
| 8 | 11 | </Page> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,9 +16,39 @@ export function onTapStretched(args) { | |||
| 16 | 16 | const label = page.getViewById<Label>("label"); | |
| 17 | 17 | var fullscreen = false; | |
| 18 | 18 | var stretched = true; | |
| 19 | - | ||
| 19 | + | ||
| 20 | 20 | page.showModal("ui-tests-app/modal-view/login-page", "context", function (username: string, password: string) { | |
| 21 | 21 | console.log(username + "/" + password); | |
| 22 | 22 | label.text = username + "/" + password; | |
| 23 | 23 | }, fullscreen, false, stretched); | |
| 24 | 24 | } | |
| 25 | + | ||
| 26 | + function openModal(page: Page, label: Label, context: string) { | ||
| 27 | + page.showModal("ui-tests-app/modal-view/login-page", context, function (username: string, password: string) { | ||
| 28 | + const result = context + "/" + username + "/" + password; | ||
| 29 | + console.log(result); | ||
| 30 | + label.text = result; | ||
| 31 | + }, false); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + export function onTapSecondModalInCB(args) { | ||
| 35 | + const page = <Page>args.object.page; | ||
| 36 | + const label = page.getViewById<Label>("label"); | ||
| 37 | + page.showModal("ui-tests-app/modal-view/login-page", "First", function (username: string, password: string) { | ||
| 38 | + const result = "First/" + username + "/" + password; | ||
| 39 | + console.log(result); | ||
| 40 | + label.text = result; | ||
| 41 | + | ||
| 42 | + // Open second modal in the close callback of the first one. | ||
| 43 | + openModal(page, label, "Second"); | ||
| 44 | + }); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + export function onTapSecondModalInTimer(args) { | ||
| 48 | + const page = <Page>args.object.page; | ||
| 49 | + const label = page.getViewById<Label>("label"); | ||
| 50 | + openModal(page, label, "First"); | ||
| 51 | + | ||
| 52 | + // Open second modal 1s after the first one. | ||
| 53 | + setTimeout(() => openModal(page, label, "Second"), 1000); | ||
| 54 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,10 @@ | |||
| 3 | 3 | <Button text="Login (pop-up)" tap="onTap" /> | |
| 4 | 4 | <Button text="Login (full-screen)" tap="onTap" /> | |
| 5 | 5 | <Button text="Login (pop-up-stretched)" tap="onTapStretched" /> | |
| 6 | + | ||
| 7 | + <Button text="Login (second modal in cb)" tap="onTapSecondModalInCB" /> | ||
| 8 | + <Button text="Login (second modal in timer)" tap="onTapSecondModalInTimer" /> | ||
| 9 | + | ||
| 6 | 10 | <Label id="label" text="Anonymous"/> | |
| 7 | 11 | </StackLayout> | |
| 8 | 12 | </Page> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -738,6 +738,7 @@ export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() { | |||
| 738 | 738 | TKUnit.assertTrue(ctx.shownModally, "Modal-page must be shown!"); | |
| 739 | 739 | TKUnit.assertEqual(returnValue, "return value", "Modal-page must return value!"); | |
| 740 | 740 | modalClosed = true; | |
| 741 | + TKUnit.assertNull(masterPage.modal, "currentPage.modal should be undefined when no modal page is shown!"); | ||
| 741 | 742 | } | |
| 742 | 743 | ||
| 743 | 744 | let modalPage: Page; | |
@@ -758,7 +759,6 @@ export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() { | |||
| 758 | 759 | const onModalUnloaded = function (args: EventData) { | |
| 759 | 760 | modalUnloaded++; | |
| 760 | 761 | modalPage.off(Page.unloadedEvent, onModalUnloaded); | |
| 761 | - TKUnit.assertNull(masterPage.modal, "currentPage.modal should be undefined when no modal page is shown!"); | ||
| 762 | 762 | } | |
| 763 | 763 | ||
| 764 | 764 | const navigatedToEventHandler = function (args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,6 @@ export function test_WhenShowingModalPageUnloadedIsNotFiredForTheMasterPage() { | |||
| 37 | 37 | let onModalUnloaded = function (args: EventData) { | |
| 38 | 38 | modalUnloaded++; | |
| 39 | 39 | modalPage.off(Page.unloadedEvent, onModalUnloaded); | |
| 40 | - TKUnit.assertNull(masterPage.modal, "currentPage.modal should be undefined when no modal page is shown!"); | ||
| 41 | 40 | } | |
| 42 | 41 | ||
| 43 | 42 | var navigatedToEventHandler = function (args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -225,10 +225,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 225 | 225 | const animated = arguments[4]; | |
| 226 | 226 | const stretched = arguments[5]; | |
| 227 | 227 | ||
| 228 | - const view: ViewDefinition = firstAgrument instanceof ViewCommon | ||
| 229 | - ? firstAgrument : createViewFromEntry({ moduleName: firstAgrument }); | ||
| 228 | + const view = firstAgrument instanceof ViewCommon | ||
| 229 | + ? firstAgrument : <ViewCommon>createViewFromEntry({ moduleName: firstAgrument }); | ||
| 230 | 230 | ||
| 231 | - (<ViewCommon>view)._showNativeModalView(this, context, closeCallback, fullscreen, animated, stretched); | ||
| 231 | + view._showNativeModalView(this, context, closeCallback, fullscreen, animated, stretched); | ||
| 232 | 232 | return view; | |
| 233 | 233 | } | |
| 234 | 234 | } | |
@@ -256,27 +256,29 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 256 | 256 | this._modalParent = parent; | |
| 257 | 257 | this._modalContext = context; | |
| 258 | 258 | const that = this; | |
| 259 | - this._closeModalCallback = function () { | ||
| 259 | + this._closeModalCallback = function (...originalArgs) { | ||
| 260 | 260 | if (that._closeModalCallback) { | |
| 261 | 261 | const modalIndex = _rootModalViews.indexOf(that); | |
| 262 | 262 | _rootModalViews.splice(modalIndex); | |
| 263 | - that._hideNativeModalView(parent); | ||
| 264 | - that._modalParent = null; | ||
| 265 | - that._modalContext = null; | ||
| 266 | - that._closeModalCallback = null; | ||
| 267 | - that._dialogClosed(); | ||
| 268 | - parent._modal = null; | ||
| 269 | - | ||
| 270 | - if (typeof closeCallback === "function") { | ||
| 271 | - closeCallback.apply(undefined, arguments); | ||
| 263 | + | ||
| 264 | + const whenClosedCallback = () => { | ||
| 265 | + that._modalParent = null; | ||
| 266 | + that._modalContext = null; | ||
| 267 | + that._closeModalCallback = null; | ||
| 268 | + that._dialogClosed(); | ||
| 269 | + parent._modal = null; | ||
| 270 | + | ||
| 271 | + if (typeof closeCallback === "function") { | ||
| 272 | + closeCallback.apply(undefined, originalArgs); | ||
| 273 | + } | ||
| 272 | 274 | } | |
| 275 | + | ||
| 276 | + that._hideNativeModalView(parent, whenClosedCallback); | ||
| 273 | 277 | } | |
| 274 | 278 | }; | |
| 275 | 279 | } | |
| 276 | 280 | ||
| 277 | - protected _hideNativeModalView(parent: ViewCommon) { | ||
| 278 | - // | ||
| 279 | - } | ||
| 281 | + protected abstract _hideNativeModalView(parent: ViewCommon, whenClosedCallback: () => void); | ||
| 280 | 282 | ||
| 281 | 283 | protected _raiseLayoutChangedEvent() { | |
| 282 | 284 | const args: EventData = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -613,14 +613,14 @@ export class View extends ViewCommon { | |||
| 613 | 613 | this._dialogFragment.show(parent._getRootFragmentManager(), this._domId.toString()); | |
| 614 | 614 | } | |
| 615 | 615 | ||
| 616 | - protected _hideNativeModalView(parent: View) { | ||
| 616 | + protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) { | ||
| 617 | 617 | const manager = this._dialogFragment.getFragmentManager(); | |
| 618 | 618 | if (manager) { | |
| 619 | 619 | this._dialogFragment.dismissAllowingStateLoss(); | |
| 620 | 620 | } | |
| 621 | 621 | ||
| 622 | 622 | this._dialogFragment = null; | |
| 623 | - super._hideNativeModalView(parent); | ||
| 623 | + whenClosedCallback(); | ||
| 624 | 624 | } | |
| 625 | 625 | ||
| 626 | 626 | [isEnabledProperty.setNative](value: boolean) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -380,8 +380,14 @@ export class View extends ViewCommon { | |||
| 380 | 380 | } | |
| 381 | 381 | ||
| 382 | 382 | const parentController = parentWithController.viewController; | |
| 383 | + if (parentController.presentedViewController) { | ||
| 384 | + traceWrite("Parent is already presenting view controller. Close the current modal page before showing another one!", | ||
| 385 | + traceCategories.ViewHierarchy, traceMessageType.error); | ||
| 386 | + return; | ||
| 387 | + } | ||
| 388 | + | ||
| 383 | 389 | if (!parentController.view || !parentController.view.window) { | |
| 384 | - traceWrite("Parent page is not part of the window hierarchy. Close the current modal page before showing another one!", | ||
| 390 | + traceWrite("Parent page is not part of the window hierarchy.", | ||
| 385 | 391 | traceCategories.ViewHierarchy, traceMessageType.error); | |
| 386 | 392 | return; | |
| 387 | 393 | } | |
@@ -426,7 +432,7 @@ export class View extends ViewCommon { | |||
| 426 | 432 | } | |
| 427 | 433 | } | |
| 428 | 434 | ||
| 429 | - protected _hideNativeModalView(parent: View) { | ||
| 435 | + protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) { | ||
| 430 | 436 | if (!parent || !parent.viewController) { | |
| 431 | 437 | traceError("Trying to hide modal view but no parent with viewController specified.") | |
| 432 | 438 | return; | |
@@ -435,8 +441,7 @@ export class View extends ViewCommon { | |||
| 435 | 441 | const parentController = parent.viewController; | |
| 436 | 442 | const animated = (<any>this.viewController).animated; | |
| 437 | 443 | ||
| 438 | - super._hideNativeModalView(parent); | ||
| 439 | - parentController.dismissModalViewControllerAnimated(animated); | ||
| 444 | + parentController.dismissViewControllerAnimatedCompletion(animated, whenClosedCallback); | ||
| 440 | 445 | } | |
| 441 | 446 | ||
| 442 | 447 | [isEnabledProperty.getDefault](): boolean { | |
@@ -907,11 +912,11 @@ export namespace ios { | |||
| 907 | 912 | const parentPageInsetsTop = parent.nativeViewProtected.safeAreaInsets.top; | |
| 908 | 913 | const currentInsetsTop = this.view.safeAreaInsets.top; | |
| 909 | 914 | const additionalInsetsTop = Math.max(parentPageInsetsTop - currentInsetsTop, 0); | |
| 910 | - | ||
| 915 | + | ||
| 911 | 916 | const parentPageInsetsBottom = parent.nativeViewProtected.safeAreaInsets.bottom; | |
| 912 | 917 | const currentInsetsBottom = this.view.safeAreaInsets.bottom; | |
| 913 | 918 | const additionalInsetsBottom = Math.max(parentPageInsetsBottom - currentInsetsBottom, 0); | |
| 914 | - | ||
| 919 | + | ||
| 915 | 920 | if (additionalInsetsTop > 0 || additionalInsetsBottom > 0) { | |
| 916 | 921 | const additionalInsets = new UIEdgeInsets({ top: additionalInsetsTop, left: 0, bottom: additionalInsetsBottom, right: 0 }); | |
| 917 | 922 | this.additionalSafeAreaInsets = additionalInsets; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments