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

fix(modal): innerView.closeModal(...) not passing back context (#5833) · NativeScript/NativeScript@1365f13 · GitHub

Commit 1365f13

Browse files
authored
fix(modal): innerView.closeModal(...) not passing back context (#5833)
1 parent 3f8af4c commit 1365f13

4 files changed

Lines changed: 85 additions & 5 deletions

File tree

‎tests/app/ui/page/page-tests-common.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Label } from "tns-core-modules/ui/label";
2424
import { Color } from "tns-core-modules/color";
2525
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view/tab-view";
2626
import { _resetRootView, getRootView } from "tns-core-modules/application";
27+
import { Button } from "tns-core-modules/ui/button/button";
2728

2829
export function addLabelToPage(page: Page, text?: string) {
2930
const label = new Label();
@@ -421,6 +422,84 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage(
421422
page.off(Label.loadedEvent, navigatedEventHandler);
422423
}
423424

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+
424503
export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() {
425504
let modalClosed = false;
426505

‎tns-core-modules/ui/core/view-base/view-base.d.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ export abstract class ViewBase extends Observable {
141141

142142
/**
143143
* 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.
144145
*/
145-
closeModal(): void;
146+
closeModal(context?: any): void;
146147

147148
public effectiveMinWidth: number;
148149
public effectiveMinHeight: number;

‎tns-core-modules/ui/core/view-base/view-base.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
949949
return parent && parent.showModal(...args);
950950
}
951951

952-
public closeModal(): void {
952+
public closeModal(...args): void {
953953
const parent = this.parent;
954954
if (parent) {
955-
parent.closeModal();
955+
parent.closeModal(...args);
956956
}
957957
}
958958

‎tns-core-modules/ui/core/view/view-common.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
232232
}
233233
}
234234

235-
public closeModal() {
235+
public closeModal(...args) {
236236
let closeCallback = this._closeModalCallback;
237237
if (closeCallback) {
238238
closeCallback.apply(undefined, arguments);
239239
} else {
240240
let parent = this.parent;
241241
if (parent) {
242-
parent.closeModal();
242+
parent.closeModal(...args);
243243
}
244244
}
245245
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL