mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(modal): exception when calling ViewBase.showModal(...) (#5737)
This commit is contained in:
@@ -421,6 +421,110 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage(
|
||||
page.off(Label.loadedEvent, navigatedEventHandler);
|
||||
}
|
||||
|
||||
export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() {
|
||||
let modalClosed = false;
|
||||
|
||||
const modalCloseCallback = function (returnValue: any) {
|
||||
modalClosed = true;
|
||||
}
|
||||
|
||||
const createTabItems = function(count: number) {
|
||||
var items = new Array<TabViewItem>();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var label = new Label();
|
||||
label.text = "Tab " + i;
|
||||
var tabEntry = new TabViewItem();
|
||||
tabEntry.title = "Tab " + i;
|
||||
tabEntry.view = label;
|
||||
|
||||
items.push(tabEntry);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
const modalPageShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const page = <Page>args.object;
|
||||
page.off(View.shownModallyEvent, modalPageShownModallyEventHandler);
|
||||
args.closeCallback();
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
const modalPage = new Page();
|
||||
modalPage.id = "modalPage_test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal";
|
||||
modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler);
|
||||
const tabViewItem = (<TabView>page.content).items[0];
|
||||
tabViewItem.showModal(modalPage, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal";
|
||||
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler)
|
||||
|
||||
const tabView = new TabView();
|
||||
tabView.items = createTabItems(2);
|
||||
masterPage.content = tabView;
|
||||
|
||||
return masterPage;
|
||||
};
|
||||
|
||||
helper.navigate(masterPageFactory);
|
||||
|
||||
TKUnit.waitUntilReady(() => modalClosed);
|
||||
}
|
||||
|
||||
export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
|
||||
let navigatedTo = false;
|
||||
|
||||
const createTabItems = function(count: number) {
|
||||
var items = new Array<TabViewItem>();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
var label = new Label();
|
||||
label.text = "Tab " + i;
|
||||
var tabEntry = new TabViewItem();
|
||||
tabEntry.title = "Tab " + i;
|
||||
tabEntry.view = label;
|
||||
|
||||
items.push(tabEntry);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
const hostPage = <Page>args.object;
|
||||
const tabViewItem = (<TabView>page.content).items[0];
|
||||
TKUnit.assertThrows(() => tabViewItem.showModal());
|
||||
|
||||
navigatedTo = true;
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow";
|
||||
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler)
|
||||
|
||||
const tabView = new TabView();
|
||||
tabView.items = createTabItems(2);
|
||||
masterPage.content = tabView;
|
||||
|
||||
return masterPage;
|
||||
};
|
||||
|
||||
helper.navigate(masterPageFactory);
|
||||
|
||||
TKUnit.waitUntilReady(() => navigatedTo);
|
||||
}
|
||||
|
||||
export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
|
||||
let page1;
|
||||
let page2;
|
||||
|
||||
@@ -946,9 +946,9 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
||||
}
|
||||
}
|
||||
|
||||
public showModal(): ViewBase {
|
||||
public showModal(...args): ViewBase {
|
||||
const parent = this.parent;
|
||||
return parent && parent.showModal();
|
||||
return parent && parent.showModal(...args);
|
||||
}
|
||||
|
||||
public closeModal(): void {
|
||||
|
||||
Reference in New Issue
Block a user