Resolved Issue #1242: Add Page showingModally event.

This commit is contained in:
Rossen Hristov
2015-12-12 16:42:23 +02:00
parent 55cbbb977a
commit d2c7b9968a
8 changed files with 40 additions and 4 deletions

View File

@ -9,6 +9,15 @@ var page: pages.Page;
var usernameTextField: textField.TextField;
var passwordTextField: textField.TextField;
export function onShowingModally(args: observable.EventData) {
console.log(">>> login-page.onShowingModally");
var modalPage = <pages.Page>args.object;
if (modalPage.ios && modalPage.ios.modalPresentationStyle === UIModalPresentationStyle.UIModalPresentationFullScreen) {
console.log(">>> Setting modalPage.ios.modalPresentationStyle to UIModalPresentationStyle.UIModalPresentationOverFullScreen");
modalPage.ios.modalPresentationStyle = UIModalPresentationStyle.UIModalPresentationOverFullScreen;
}
}
export function onShownModally(args: pages.ShownModallyData) {
console.log(">>> login-page.onShownModally, context: " + args.context);

View File

@ -1,4 +1,5 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
showingModally="onShowingModally"
shownModally="onShownModally"
navigatingTo="onNavigatingTo"
loaded="onLoaded"

View File

@ -3,9 +3,15 @@ import TKUnit = require("../../TKUnit");
import frame = require("ui/frame");
import page = require("ui/page");
var modalPage: page.Page;
export function onShowingModally(args) {
modalPage = <page.Page>args.object;
}
export function onShownModally(args: ShownModallyData) {
TKUnit.assertNotNull(modalPage);
TKUnit.wait(0.100);
var modalPage = <page.Page>args.object;
if (args.context) {
args.context.shownModally = true;
}

View File

@ -1,4 +1,4 @@
<Page shownModally="onShownModally">
<Page showingModally="onShowingModally" shownModally="onShownModally">
<StackLayout>
<Label text="Modal Page" />
</StackLayout>

View File

@ -35,6 +35,7 @@ export class Page extends ContentView implements dts.Page {
public static navigatingFromEvent = "navigatingFrom";
public static navigatedFromEvent = "navigatedFrom";
public static shownModallyEvent = "shownModally";
public static showingModallyEvent = "showingModally";
protected _closeModalCallback: Function;
@ -251,6 +252,13 @@ export class Page extends ContentView implements dts.Page {
});
}
protected _raiseShowingModallyEvent() {
this.notify({
eventName: Page.showingModallyEvent,
object: this
});
}
public _getStyleScope(): styleScope.StyleScope {
return this._styleScope;
}

View File

@ -125,8 +125,9 @@ export class Page extends pageCommon.Page {
this._dialogFragment = new DialogFragmentClass(this, fullscreen, function () {
that.closeModal();
});
this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), "dialog");
super._raiseShowingModallyEvent();
this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), "dialog");
super._raiseShownModallyEvent(parent, context, closeCallback);
}

12
ui/page/page.d.ts vendored
View File

@ -61,6 +61,11 @@ declare module "ui/page" {
*/
public static actionBarHiddenProperty: dependencyObservable.Property;
/**
* String value used when hooking to showingModally event.
*/
public static showingModallyEvent: string;
/**
* String value used when hooking to shownModally event.
*/
@ -159,7 +164,12 @@ declare module "ui/page" {
on(event: "navigatedFrom", callback: (args: NavigatedData) => void, thisArg?: any);
/**
* Raised when the page is shown as a modal dialog.
* Raised before the page is shown as a modal dialog.
*/
on(event: "showingModally", callback: (args: observable.EventData) => void, thisArg?: any);
/**
* Raised after the page is shown as a modal dialog.
*/
on(event: "shownModally", callback: (args: ShownModallyData) => void, thisArg?: any);

View File

@ -241,6 +241,7 @@ export class Page extends pageCommon.Page {
this._UIModalPresentationFormSheet = true;
}
super._raiseShowingModallyEvent();
var that = this;
parent.ios.presentViewControllerAnimatedCompletion(this._ios, false, function completion() {
that._raiseShownModallyEvent(parent, context, closeCallback);