mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Fixed #727: Provide a way to get a reference to the currently showing modal page instance.
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
import pages = require("ui/page");
|
import pages = require("ui/page");
|
||||||
import textField = require("ui/text-field");
|
import textField = require("ui/text-field");
|
||||||
|
import frame = require("ui/frame");
|
||||||
|
|
||||||
var context: any;
|
var context: any;
|
||||||
var closeCallback: Function;
|
var closeCallback: Function;
|
||||||
@ -13,6 +14,11 @@ export function onShownModally(args: pages.ShownModallyData) {
|
|||||||
console.log("login-page.onShownModally, context: " + args.context);
|
console.log("login-page.onShownModally, context: " + args.context);
|
||||||
context = args.context;
|
context = args.context;
|
||||||
closeCallback = args.closeCallback;
|
closeCallback = args.closeCallback;
|
||||||
|
var modalPage = <pages.Page>args.object;
|
||||||
|
|
||||||
|
if (frame.topmost().currentPage.modal !== args.object) {
|
||||||
|
throw new Error(`frame.topmost().currentPage.modal.id: ${frame.topmost().currentPage.modal.id}; modalPage.id: ${modalPage.id}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onLoaded(args: observable.EventData) {
|
export function onLoaded(args: observable.EventData) {
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import {ShownModallyData} from "ui/page";
|
import {ShownModallyData} from "ui/page";
|
||||||
import TKUnit = require("../../TKUnit");
|
import TKUnit = require("../../TKUnit");
|
||||||
|
import frame = require("ui/frame");
|
||||||
|
import page = require("ui/page");
|
||||||
|
|
||||||
export function onShownModally(args: ShownModallyData) {
|
export function onShownModally(args: ShownModallyData) {
|
||||||
TKUnit.wait(0.350);
|
TKUnit.wait(0.100);
|
||||||
|
var modalPage = <page.Page>args.object;
|
||||||
args.context.shownModally = true;
|
args.context.shownModally = true;
|
||||||
|
TKUnit.assert(frame.topmost().currentPage.modal = modalPage, "frame.topmost().currentPage.modal should be equal to the page instance on page.shownModally event handler.");
|
||||||
args.closeCallback("return value");
|
args.closeCallback("return value");
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import TKUnit = require("../../TKUnit");
|
|||||||
import LabelModule = require("ui/label");
|
import LabelModule = require("ui/label");
|
||||||
import helper = require("../helper");
|
import helper = require("../helper");
|
||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
|
import frame = require("ui/frame");
|
||||||
|
|
||||||
global.moduleMerge(PageTestCommon, exports);
|
global.moduleMerge(PageTestCommon, exports);
|
||||||
|
|
||||||
@ -35,11 +36,13 @@ export function test_WhenPageIsLoadedItCanShowAnotherPageAsModal() {
|
|||||||
var modalCloseCallback = function (returnValue: any) {
|
var modalCloseCallback = function (returnValue: any) {
|
||||||
TKUnit.assert(ctx.shownModally, "Modal-page must be shown!");
|
TKUnit.assert(ctx.shownModally, "Modal-page must be shown!");
|
||||||
TKUnit.assert(returnValue === "return value", "Modal-page must return value!");
|
TKUnit.assert(returnValue === "return value", "Modal-page must return value!");
|
||||||
TKUnit.wait(0.350);
|
TKUnit.assert(!frame.topmost().currentPage.modal, "frame.topmost().currentPage.modal should be undefined when no modal page is shown!");
|
||||||
|
TKUnit.wait(0.100);
|
||||||
modalClosed = true;
|
modalClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var loadedEventHandler = function (args) {
|
var loadedEventHandler = function (args) {
|
||||||
|
TKUnit.assert(!frame.topmost().currentPage.modal, "frame.topmost().currentPage.modal should be undefined when no modal page is shown!");
|
||||||
var basePath = "ui/page/";
|
var basePath = "ui/page/";
|
||||||
args.object.showModal(basePath + "modal-page", ctx, modalCloseCallback, false);
|
args.object.showModal(basePath + "modal-page", ctx, modalCloseCallback, false);
|
||||||
};
|
};
|
||||||
|
@ -44,6 +44,8 @@ export class Page extends ContentView implements dts.Page {
|
|||||||
private _styleScope: styleScope.StyleScope = new styleScope.StyleScope();
|
private _styleScope: styleScope.StyleScope = new styleScope.StyleScope();
|
||||||
private _actionBar: ActionBar;
|
private _actionBar: ActionBar;
|
||||||
|
|
||||||
|
private _modal: Page;
|
||||||
|
|
||||||
constructor(options?: dts.Options) {
|
constructor(options?: dts.Options) {
|
||||||
super(options);
|
super(options);
|
||||||
this.actionBar = new ActionBar();
|
this.actionBar = new ActionBar();
|
||||||
@ -217,6 +219,10 @@ export class Page extends ContentView implements dts.Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get modal(): Page {
|
||||||
|
return this._modal;
|
||||||
|
}
|
||||||
|
|
||||||
public _addChildFromBuilder(name: string, value: any) {
|
public _addChildFromBuilder(name: string, value: any) {
|
||||||
if (value instanceof ActionBar) {
|
if (value instanceof ActionBar) {
|
||||||
this.actionBar = value;
|
this.actionBar = value;
|
||||||
@ -227,6 +233,7 @@ export class Page extends ContentView implements dts.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
|
protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
|
||||||
|
parent._modal = this;
|
||||||
var that = this;
|
var that = this;
|
||||||
this._closeModalCallback = function () {
|
this._closeModalCallback = function () {
|
||||||
if (that._closeModalCallback) {
|
if (that._closeModalCallback) {
|
||||||
@ -240,7 +247,7 @@ export class Page extends ContentView implements dts.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected _hideNativeModalView(parent: Page) {
|
protected _hideNativeModalView(parent: Page) {
|
||||||
//
|
parent._modal = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _raiseShownModallyEvent(parent: Page, context: any, closeCallback: Function) {
|
protected _raiseShownModallyEvent(parent: Page, context: any, closeCallback: Function) {
|
||||||
|
@ -137,6 +137,8 @@ export class Page extends pageCommon.Page {
|
|||||||
this.onUnloaded();
|
this.onUnloaded();
|
||||||
this._isAddedToNativeVisualTree = false;
|
this._isAddedToNativeVisualTree = false;
|
||||||
this._onDetached(true);
|
this._onDetached(true);
|
||||||
|
|
||||||
|
super._hideNativeModalView(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _updateActionBar(hidden: boolean) {
|
public _updateActionBar(hidden: boolean) {
|
||||||
|
7
ui/page/page.d.ts
vendored
7
ui/page/page.d.ts
vendored
@ -173,9 +173,14 @@ declare module "ui/page" {
|
|||||||
showModal();
|
showModal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the current modal dialog that this page is showing.
|
* Closes the current modal view that this page is showing.
|
||||||
*/
|
*/
|
||||||
closeModal();
|
closeModal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current modal view that this page is showing (is parent of), if any.
|
||||||
|
*/
|
||||||
|
modal: Page;
|
||||||
|
|
||||||
//@private
|
//@private
|
||||||
|
|
||||||
|
@ -226,6 +226,8 @@ export class Page extends pageCommon.Page {
|
|||||||
this._UIModalPresentationFormSheet = false;
|
this._UIModalPresentationFormSheet = false;
|
||||||
parent.requestLayout();
|
parent.requestLayout();
|
||||||
parent._ios.dismissModalViewControllerAnimated(false);
|
parent._ios.dismissModalViewControllerAnimated(false);
|
||||||
|
|
||||||
|
super._hideNativeModalView(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _updateActionBar(hidden: boolean) {
|
public _updateActionBar(hidden: boolean) {
|
||||||
|
Reference in New Issue
Block a user