| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ import { Label } from "tns-core-modules/ui/label"; | |||
| 24 | 24 | import { Color } from "tns-core-modules/color"; | |
| 25 | 25 | import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view/tab-view"; | |
| 26 | 26 | import { _resetRootView, getRootView } from "tns-core-modules/application"; | |
| 27 | + import { Button } from "tns-core-modules/ui/button/button"; | ||
| 27 | 28 | ||
| 28 | 29 | export function addLabelToPage(page: Page, text?: string) { | |
| 29 | 30 | const label = new Label(); | |
@@ -421,6 +422,84 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage( | |||
| 421 | 422 | page.off(Label.loadedEvent, navigatedEventHandler); | |
| 422 | 423 | } | |
| 423 | 424 | ||
| 425 | + export function test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult() { | ||
| 426 | + _test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => | ||
| 427 | + { | ||
| 428 | + const page = <Page>args.object; | ||
| 429 | + const button = <Button>page.content; | ||
| 430 | + return button.closeModal.bind(button); | ||
| 431 | + }, "return value"); | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + export function test_WhenInnerViewCallsCloseModal_WithoutArguments_ShouldWork() { | ||
| 435 | + _test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => | ||
| 436 | + { | ||
| 437 | + const page = <Page>args.object; | ||
| 438 | + const button = <Button>page.content; | ||
| 439 | + return button.closeModal.bind(button); | ||
| 440 | + }); | ||
| 441 | + } | ||
| 442 | + | ||
| 443 | + export function test_WhenInnerViewCallsCloseCallback_WithArguments_ShouldPassResult() { | ||
| 444 | + _test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => | ||
| 445 | + { | ||
| 446 | + return args.closeCallback; | ||
| 447 | + }, "return value"); | ||
| 448 | + } | ||
| 449 | + | ||
| 450 | + export function test_WhenInnerViewCallsCloseCallback_WithoutArguments_ShouldWork() { | ||
| 451 | + _test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => | ||
| 452 | + { | ||
| 453 | + return args.closeCallback; | ||
| 454 | + }); | ||
| 455 | + } | ||
| 456 | + | ||
| 457 | + function _test_WhenInnerViewCallsCloseModal(closeModalGetter: (ShownModallyData) => Function, result?: any) { | ||
| 458 | + let modalClosedWithResult = false; | ||
| 459 | + | ||
| 460 | + const modalCloseCallback = function (returnValue: any) { | ||
| 461 | + modalClosedWithResult = returnValue === result; | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + const modalPageShownModallyEventHandler = function(args: ShownModallyData) { | ||
| 465 | + const page = <Page>args.object; | ||
| 466 | + page.off(View.shownModallyEvent, modalPageShownModallyEventHandler); | ||
| 467 | + | ||
| 468 | + closeModalGetter(args)(result); | ||
| 469 | + } | ||
| 470 | + | ||
| 471 | + const hostNavigatedToEventHandler = function(args: NavigatedData) { | ||
| 472 | + const page = <Page>args.object; | ||
| 473 | + page.off(Page.navigatedToEvent, hostNavigatedToEventHandler); | ||
| 474 | + | ||
| 475 | + const modalPage = new Page(); | ||
| 476 | + modalPage.id = "modalPage_test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult"; | ||
| 477 | + modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler); | ||
| 478 | + | ||
| 479 | + const button = new Button(); | ||
| 480 | + button.text = "CLOSE MODAL"; | ||
| 481 | + modalPage.content = button; | ||
| 482 | + | ||
| 483 | + (<Button>page.content).showModal(modalPage, {}, modalCloseCallback); | ||
| 484 | + } | ||
| 485 | + | ||
| 486 | + const masterPageFactory = function(): Page { | ||
| 487 | + const masterPage = new Page(); | ||
| 488 | + masterPage.id = "masterPage_test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult"; | ||
| 489 | + masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler) | ||
| 490 | + | ||
| 491 | + const button = new Button(); | ||
| 492 | + button.text = "TAP"; | ||
| 493 | + masterPage.content = button; | ||
| 494 | + | ||
| 495 | + return masterPage; | ||
| 496 | + }; | ||
| 497 | + | ||
| 498 | + helper.navigate(masterPageFactory); | ||
| 499 | + | ||
| 500 | + TKUnit.waitUntilReady(() => modalClosedWithResult); | ||
| 501 | + } | ||
| 502 | + | ||
| 424 | 503 | export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() { | |
| 425 | 504 | let modalClosed = false; | |
| 426 | 505 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,8 +141,9 @@ export abstract class ViewBase extends Observable { | |||
| 141 | 141 | ||
| 142 | 142 | /** | |
| 143 | 143 | * Closes the current modal view that this page is showing. | |
| 144 | + * @param context - Any context you want to pass back to the host when closing the modal view. | ||
| 144 | 145 | */ | |
| 145 | - closeModal(): void; | ||
| 146 | + closeModal(context?: any): void; | ||
| 146 | 147 | ||
| 147 | 148 | public effectiveMinWidth: number; | |
| 148 | 149 | public effectiveMinHeight: number; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -949,10 +949,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition | |||
| 949 | 949 | return parent && parent.showModal(...args); | |
| 950 | 950 | } | |
| 951 | 951 | ||
| 952 | - public closeModal(): void { | ||
| 952 | + public closeModal(...args): void { | ||
| 953 | 953 | const parent = this.parent; | |
| 954 | 954 | if (parent) { | |
| 955 | - parent.closeModal(); | ||
| 955 | + parent.closeModal(...args); | ||
| 956 | 956 | } | |
| 957 | 957 | } | |
| 958 | 958 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,14 +232,14 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 232 | 232 | } | |
| 233 | 233 | } | |
| 234 | 234 | ||
| 235 | - public closeModal() { | ||
| 235 | + public closeModal(...args) { | ||
| 236 | 236 | let closeCallback = this._closeModalCallback; | |
| 237 | 237 | if (closeCallback) { | |
| 238 | 238 | closeCallback.apply(undefined, arguments); | |
| 239 | 239 | } else { | |
| 240 | 240 | let parent = this.parent; | |
| 241 | 241 | if (parent) { | |
| 242 | - parent.closeModal(); | ||
| 242 | + parent.closeModal(...args); | ||
| 243 | 243 | } | |
| 244 | 244 | } | |
| 245 | 245 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments