mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(view): added iOS parameter for modal presentation style (#6409)
* feat(view): added iOS parameter for modal presentation style * Now passing options to showModal in one argument * refactor: Move context and close in modal options * chore: Comments added for UIModalPresentationStyle.Popover case * refactor: Use modalOptions in e2e demo * chore: fix pbroken test
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// >> article-require-page-module
|
||||
// >> article-require-page-module
|
||||
import { Page, ShownModallyData, NavigatedData } from "tns-core-modules/ui/page";
|
||||
// FrameModule is needed in order to have an option to navigate to the new page.
|
||||
import { topmost, NavigationEntry } from "tns-core-modules/ui/frame";
|
||||
@@ -422,8 +422,7 @@ export function test_WhenPageIsNavigatedToFrameCurrentPageIsNowTheSameAsThePage(
|
||||
}
|
||||
|
||||
export function test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult() {
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) =>
|
||||
{
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => {
|
||||
const page = <Page>args.object;
|
||||
const button = <Button>page.content;
|
||||
return button.closeModal.bind(button);
|
||||
@@ -431,8 +430,7 @@ export function test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult
|
||||
}
|
||||
|
||||
export function test_WhenInnerViewCallsCloseModal_WithoutArguments_ShouldWork() {
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) =>
|
||||
{
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => {
|
||||
const page = <Page>args.object;
|
||||
const button = <Button>page.content;
|
||||
return button.closeModal.bind(button);
|
||||
@@ -440,15 +438,13 @@ export function test_WhenInnerViewCallsCloseModal_WithoutArguments_ShouldWork()
|
||||
}
|
||||
|
||||
export function test_WhenInnerViewCallsCloseCallback_WithArguments_ShouldPassResult() {
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) =>
|
||||
{
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => {
|
||||
return args.closeCallback;
|
||||
}, "return value");
|
||||
}
|
||||
|
||||
export function test_WhenInnerViewCallsCloseCallback_WithoutArguments_ShouldWork() {
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) =>
|
||||
{
|
||||
_test_WhenInnerViewCallsCloseModal((args: ShownModallyData) => {
|
||||
return args.closeCallback;
|
||||
});
|
||||
}
|
||||
@@ -460,14 +456,14 @@ function _test_WhenInnerViewCallsCloseModal(closeModalGetter: (ShownModallyData)
|
||||
modalClosedWithResult = returnValue === result;
|
||||
}
|
||||
|
||||
const modalPageShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalPageShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
const page = <Page>args.object;
|
||||
page.off(View.shownModallyEvent, modalPageShownModallyEventHandler);
|
||||
|
||||
|
||||
closeModalGetter(args)(result);
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args: NavigatedData) {
|
||||
const hostNavigatedToEventHandler = function (args: NavigatedData) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -482,11 +478,11 @@ function _test_WhenInnerViewCallsCloseModal(closeModalGetter: (ShownModallyData)
|
||||
(<Button>page.content).showModal(modalPage, {}, modalCloseCallback);
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenInnerViewCallsCloseModal_WithArguments_ShouldPassResult";
|
||||
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler)
|
||||
|
||||
|
||||
const button = new Button();
|
||||
button.text = "TAP";
|
||||
masterPage.content = button;
|
||||
@@ -511,7 +507,7 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal()
|
||||
modalClosed = true;
|
||||
}
|
||||
|
||||
const createTabItems = function(count: number) {
|
||||
const createTabItems = function (count: number) {
|
||||
var items = new Array<TabViewItem>();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -527,13 +523,13 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal()
|
||||
return items;
|
||||
}
|
||||
|
||||
const modalPageShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalPageShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
const page = <Page>args.object;
|
||||
page.off(View.shownModallyEvent, modalPageShownModallyEventHandler);
|
||||
args.closeCallback();
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -544,11 +540,11 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal()
|
||||
tabViewItem.showModal(modalPage, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
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;
|
||||
@@ -566,11 +562,14 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal()
|
||||
}
|
||||
}
|
||||
|
||||
export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
|
||||
let navigatedTo = false;
|
||||
let modalThrows = false;
|
||||
export function test_WhenViewBaseCallsShowModal_WithShowModalOptionsArguments_ShouldOpenModal() {
|
||||
let modalClosed = false;
|
||||
|
||||
const createTabItems = function(count: number) {
|
||||
const modalCloseCallback = function (returnValue: any) {
|
||||
modalClosed = true;
|
||||
}
|
||||
|
||||
const createTabItems = function (count: number) {
|
||||
var items = new Array<TabViewItem>();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -586,10 +585,69 @@ export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
|
||||
return items;
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
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_WithShowModalOptionsArguments_ShouldOpenModal";
|
||||
modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler);
|
||||
const tabViewItem = (<TabView>page.content).items[0];
|
||||
tabViewItem.showModal(modalPage, {
|
||||
context: {},
|
||||
closeCallback: modalCloseCallback,
|
||||
fullscreen: false,
|
||||
animated: false
|
||||
});
|
||||
}
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithShowModalOptionsArguments_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;
|
||||
let modalThrows = 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];
|
||||
try {
|
||||
@@ -601,11 +659,11 @@ export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() {
|
||||
navigatedTo = true;
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
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;
|
||||
@@ -667,7 +725,7 @@ export function test_WhenRootTabViewShownModallyItCanCloseModal() {
|
||||
modalClosed = true;
|
||||
}
|
||||
|
||||
const createTabItems = function(count: number) {
|
||||
const createTabItems = function (count: number) {
|
||||
var items = new Array<TabViewItem>();
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -683,11 +741,11 @@ export function test_WhenRootTabViewShownModallyItCanCloseModal() {
|
||||
return items;
|
||||
}
|
||||
|
||||
const tabViewShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const tabViewShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
args.closeCallback("return value");
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -698,7 +756,7 @@ export function test_WhenRootTabViewShownModallyItCanCloseModal() {
|
||||
page.showModal(tabView, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
const masterPageFactory = function(): Page {
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenRootTabViewShownModallyItCanCloseModal";
|
||||
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
@@ -832,11 +890,11 @@ export function test_WhenModalPageShownHostPageNavigationEventsShouldNotBeRaised
|
||||
hostNavigatedFromCount++;
|
||||
};
|
||||
|
||||
const modalPageShownModallyEventHandler = function() {
|
||||
const modalPageShownModallyEventHandler = function () {
|
||||
TKUnit.assertEqual(stack().length, 1, "Single frame should be instantiated at this point!");
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler2 = function(args: NavigatedData) {
|
||||
const hostNavigatedToEventHandler2 = function (args: NavigatedData) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler2);
|
||||
|
||||
@@ -852,7 +910,7 @@ export function test_WhenModalPageShownHostPageNavigationEventsShouldNotBeRaised
|
||||
|
||||
page.showModal(modalPage, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenModalPageShownHostPageNavigationEventsShouldNotBeRaised";
|
||||
@@ -915,12 +973,12 @@ export function test_WhenModalPageShownModalNavigationToEventsShouldBeRaised() {
|
||||
modalNavigatedFromCount++;
|
||||
};
|
||||
|
||||
const modalFrameShownModallyEventHandler = function(args) {
|
||||
const modalFrameShownModallyEventHandler = function (args) {
|
||||
const basePath = "ui/page/";
|
||||
const entry: NavigationEntry = {
|
||||
moduleName: basePath + "modal-page"
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
const modalPage = createViewFromEntry(entry) as Page;
|
||||
modalPage.on(Page.navigatingToEvent, modalNavigatingToEventHandler);
|
||||
modalPage.on(Page.navigatedToEvent, modalNavigatedToEventHandler);
|
||||
@@ -932,7 +990,7 @@ export function test_WhenModalPageShownModalNavigationToEventsShouldBeRaised() {
|
||||
|
||||
let modalFrame;
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -941,7 +999,7 @@ export function test_WhenModalPageShownModalNavigationToEventsShouldBeRaised() {
|
||||
|
||||
page.showModal(modalFrame, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenModalPageShownModalNavigationToEventsShouldBeRaised";
|
||||
@@ -981,11 +1039,11 @@ export function test_WhenModalFrameShownModalEventsRaisedOnRootModalFrame() {
|
||||
ready = true;
|
||||
}
|
||||
|
||||
const modalFrameShowingModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalFrameShowingModallyEventHandler = function (args: ShownModallyData) {
|
||||
showingModallyCount++;
|
||||
}
|
||||
|
||||
const modalFrameShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalFrameShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
shownModallyCount++;
|
||||
TKUnit.assertEqual(stack().length, 2, "Host and modal frame should be instantiated at this point!");
|
||||
|
||||
@@ -994,7 +1052,7 @@ export function test_WhenModalFrameShownModalEventsRaisedOnRootModalFrame() {
|
||||
|
||||
let modalFrame;
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -1016,7 +1074,7 @@ export function test_WhenModalFrameShownModalEventsRaisedOnRootModalFrame() {
|
||||
|
||||
page.showModal(modalFrame, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenModalFrameShownModalEventsRaisedOnRootModalFrame";
|
||||
@@ -1051,11 +1109,11 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage() {
|
||||
ready = true;
|
||||
}
|
||||
|
||||
const modalPageShowingModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalPageShowingModallyEventHandler = function (args: ShownModallyData) {
|
||||
showingModallyCount++;
|
||||
}
|
||||
|
||||
const modalPageShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalPageShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
shownModallyCount++;
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -1063,7 +1121,7 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage() {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -1078,7 +1136,7 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage() {
|
||||
|
||||
page.showModal(modalPage, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
const masterPage = new Page();
|
||||
masterPage.id = "masterPage_test_WhenModalPageShownShowModalEventsRaisedOnRootModalPage";
|
||||
@@ -1114,15 +1172,15 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView()
|
||||
setTimeout(() => ready = true, 50);
|
||||
}
|
||||
|
||||
const modalTabViewShowingModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalTabViewShowingModallyEventHandler = function (args: ShownModallyData) {
|
||||
showingModallyCount++;
|
||||
}
|
||||
|
||||
const modalTabViewShownModallyEventHandler = function(args: ShownModallyData) {
|
||||
const modalTabViewShownModallyEventHandler = function (args: ShownModallyData) {
|
||||
shownModallyCount++;
|
||||
}
|
||||
|
||||
const hostNavigatedToEventHandler = function(args) {
|
||||
|
||||
const hostNavigatedToEventHandler = function (args) {
|
||||
const page = <Page>args.object;
|
||||
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
|
||||
|
||||
@@ -1139,7 +1197,7 @@ export function test_WhenModalPageShownShowModalEventsRaisedOnRootModalTabView()
|
||||
|
||||
TKUnit.assertEqual(stack().length, 2, "Host and tab modal frame should be instantiated at this point!");
|
||||
|
||||
page.showModal(modalTabView, { }, modalCloseCallback, false, false);
|
||||
page.showModal(modalTabView, {}, modalCloseCallback, false, false);
|
||||
}
|
||||
|
||||
const masterPageFactory = function (): Page {
|
||||
|
||||
Reference in New Issue
Block a user