Resolved #142: Modal views.

This commit is contained in:
Rossen Hristov
2015-05-18 14:05:19 +03:00
parent 3ac52814c7
commit 90722cfc67
17 changed files with 285 additions and 74 deletions

View File

@@ -0,0 +1,3 @@
import application = require("application");
application.mainModule = "main-page";
application.start();

View File

@@ -0,0 +1,32 @@
import observable = require("data/observable");
import pages = require("ui/page");
import textField = require("ui/text-field");
var context: any;
var closeCallback: Function;
var page: pages.Page;
var usernameTextField: textField.TextField;
var passwordTextField: textField.TextField;
export function onShownModally(args: pages.ShownModallyData) {
console.log("login-page.onShownModally, context: " + args.context);
context = args.context;
closeCallback = args.closeCallback;
}
export function onLoaded(args: observable.EventData) {
console.log("login-page.onLoaded");
page = <pages.Page>args.object;
usernameTextField = page.getViewById<textField.TextField>("username");
passwordTextField = page.getViewById<textField.TextField>("password");
}
export function onUnloaded() {
console.log("login-page.onUnloaded");
}
export function onLoginButtonTap() {
console.log("login-page.onLoginButtonTap");
closeCallback(usernameTextField.text, passwordTextField.text);
}

View File

@@ -0,0 +1,7 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" shownModally="onShownModally" loaded="onLoaded" unloaded="onUnloaded">
<StackLayout>
<TextField hint="username" id="username"/>
<TextField hint="password" id="password" secure="true"/>
<Button text="Login" tap="onLoginButtonTap"/>
</StackLayout>
</Page>

View File

@@ -0,0 +1,18 @@
import observable = require("data/observable");
import pages = require("ui/page");
import labelModule = require("ui/label");
var page: pages.Page;
var label: labelModule.Label;
export function pageLoaded(args: observable.EventData) {
page = <pages.Page>args.object;
label = page.getViewById<labelModule.Label>("label");
}
export function onTap(args: observable.EventData) {
page.showModal("./modal-views-demo/login-page", "some custom context", function(username: string, password: string) {
console.log(username + "/" + password);
label.text = username + "/" + password;
});
}

View File

@@ -0,0 +1,6 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded" id="_mainPage">
<StackLayout>
<Button text="Login" tap="onTap" />
<Label id="label" text="Anonymous"/>
</StackLayout>
</Page>

View File

@@ -0,0 +1,2 @@
{ "name" : "modal-views-demo",
"main" : "app.js" }