Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. ## Setup
  2.  
  3. * Empty `app.css`.
  4. * Run `npm install nativescript-explosionfield --save`.
  5. * Run `npm install nativescript-pulltorefresh --save`.
  6. * Have the iOS simulator running.
  7. * Have the Android app running and livesync running.
  8. * Have the Groceries web app running.
  9. * Verify the grocery list is appropriate in the default account.
  10. * Paste this in for `login.component.ts`:
  11.  
  12. ``` TypeScript
  13. import {Component} from "angular2/core";
  14.  
  15. @Component({
  16. selector: "login",
  17. template: "<Label text='Hello NativeScript'></Label>"
  18. })
  19. export class LoginPage {}
  20. ```
  21.  
  22. * Paste this in for `login-common.css`:
  23.  
  24. ``` css
  25. #container {
  26. margin-left: 30;
  27. margin-right: 30;
  28. padding-bottom: 15;
  29. background-color: white;
  30. }
  31. #logo {
  32. margin-top: 5;
  33. margin-bottom: 20;
  34. }
  35. Button, TextField {
  36. margin-left: 16;
  37. margin-right: 16;
  38. margin-bottom: 10;
  39. }
  40. #submit-button {
  41. background-color: #CB1D00;
  42. color: white;
  43. margin-top: 20;
  44. }
  45. ```
  46.  
  47. * Paste this in for `login.html`:
  48.  
  49. ``` html
  50. <GridLayout>
  51.  
  52. <GridLayout id="background" scaleX="1.6" scaleY="1.6"></GridLayout>
  53.  
  54. <StackLayout id="container" height="350">
  55. <Image [src]="isLoggingIn ? 'res://logo_login' : 'res://logo_signup'" id="logo" stretch="none" horizontalAlignment="center"></Image>
  56.  
  57. <TextField [(ngModel)]="user.email" id="email" hint="Email" keyboardType="email" autocorrect="false" autocapitalizationType="none" [color]="isLoggingIn ? 'black' : 'white'"></TextField>
  58. <TextField [(ngModel)]="user.password" id="password" secure="true" hint="Password" [color]="isLoggingIn ? 'black' : 'white'"></TextField>
  59.  
  60. <Button [text]="isLoggingIn ? 'Sign in' : 'Sign up'" id="submit-button" (tap)="submit()"></Button>
  61. <Button [text]="isLoggingIn ? 'Sign up' : 'Back to login'" (tap)="toggleDisplay()"></Button>
  62. </StackLayout>
  63.  
  64. </GridLayout>
  65. ```
  66.  
  67. * Paste this in for `app.component.ts`:
  68.  
  69. ``` TypeScript
  70. import {Component} from "angular2/core";
  71. import {RouteConfig} from "angular2/router";
  72. import {NS_ROUTER_DIRECTIVES} from "nativescript-angular/router";
  73.  
  74. import {LoginPage} from "./pages/login/login.component";
  75. import {ListPage} from "./pages/list/list.component";
  76.  
  77. @Component({
  78. selector: "main",
  79. directives: [NS_ROUTER_DIRECTIVES],
  80. template: "<page-router-outlet></page-router-outlet>"
  81. })
  82. @RouteConfig([
  83. { path: "/Login", component: LoginPage, as: "Login", useAsDefault: true },
  84. { path: "/List", component: ListPage, as: "List" }
  85. ])
  86. export class AppComponent {}
  87. ```
  88.  
  89. ## ng1
  90.  
  91. ``` TypeScript
  92. template: `
  93. <StackLayout>
  94. <TextField hint="Email Address" id="email" keyboardType="email"
  95. autocorrect="false" autocapitalizationType="none"></TextField>
  96. <TextField hint="Password" id="password" secure="true"></TextField>
  97.  
  98. <Button text="Sign in"></Button>
  99. <Button text="Sign up"></Button>
  100. </StackLayout>
  101. `
  102. ```
  103.  
  104. ## ng2
  105.  
  106. ``` css
  107. @import url("~/platform.css");
  108.  
  109. Page {
  110. background-color: white;
  111. font-size: 15;
  112. }
  113. ActionBar {
  114. background-color: black;
  115. color: white;
  116. }
  117. TextField {
  118. padding: 10;
  119. font-size: 13;
  120. }
  121. .small-spacing {
  122. margin: 5;
  123. }
  124. .medium-spacing {
  125. margin: 10;
  126. }
  127. ```
  128.  
  129. ## ng3
  130.  
  131. ``` TypeScript
  132. import {Component, OnInit} from "angular2/core";
  133. import {topmost} from "ui/frame";
  134. import {Page} from "ui/page";
  135.  
  136. import {User} from "../../shared/user/user";
  137.  
  138. @Component({
  139. selector: "login",
  140. templateUrl: "pages/login/login.html",
  141. styleUrls: ["pages/login/login-common.css", "pages/login/login.css"]
  142. })
  143. export class LoginPage implements OnInit {
  144. user: User;
  145. isLoggingIn = true;
  146. page: Page;
  147.  
  148. ngOnInit() {
  149. this.page = <Page>topmost().currentPage;
  150. this.page.actionBarHidden = true;
  151. }
  152. }
  153. ```
  154.  
  155. ## ng4
  156.  
  157. ``` TypeScript
  158. import {Component, OnInit} from "angular2/core";
  159. import {topmost} from "ui/frame";
  160. import {Page} from "ui/page";
  161.  
  162. import {User} from "../../shared/user/user";
  163. import {UserService} from "../../shared/user/user.service";
  164.  
  165. @Component({
  166. providers: [UserService],
  167. selector: "login",
  168. templateUrl: "pages/login/login.html",
  169. styleUrls: ["pages/login/login-common.css", "pages/login/login.css"]
  170. })
  171. export class LoginPage implements OnInit {
  172. user: User;
  173. isLoggingIn = true;
  174. page: Page;
  175.  
  176. constructor(private _userService: UserService) {
  177. this.user = new User();
  178. this.user.email = "nativescriptrocks@telerik.com";
  179. this.user.password = "password";
  180. }
  181.  
  182. ngOnInit() {
  183. this.page = <Page>topmost().currentPage;
  184. this.page.actionBarHidden = true;
  185. }
  186.  
  187. submit() {
  188. this._userService.login(this.user)
  189. .subscribe(
  190. () => alert("success!"),
  191. (error) => alert("Unfortunately we could not find your account.")
  192. );
  193. }
  194. }
  195. ```
  196.  
  197. ## ng5
  198.  
  199. ``` TypeScript
  200. import {Component, OnInit} from "angular2/core";
  201. import {topmost} from "ui/frame";
  202. import {Page} from "ui/page";
  203. import {Router} from "angular2/router";
  204.  
  205. import {User} from "../../shared/user/user";
  206. import {UserService} from "../../shared/user/user.service";
  207.  
  208. @Component({
  209. providers: [UserService],
  210. selector: "login",
  211. templateUrl: "pages/login/login.html",
  212. styleUrls: ["pages/login/login-common.css", "pages/login/login.css"]
  213. })
  214. export class LoginPage implements OnInit {
  215. user: User;
  216. isLoggingIn = true;
  217. page: Page;
  218.  
  219. constructor(private _userService: UserService, private _router: Router) {
  220. this.user = new User();
  221. this.user.email = "nativescriptrocks@telerik.com";
  222. this.user.password = "password";
  223. }
  224.  
  225. ngOnInit() {
  226. this.page = <Page>topmost().currentPage;
  227. this.page.actionBarHidden = true;
  228. }
  229.  
  230. submit() {
  231. this._userService.login(this.user)
  232. .subscribe(
  233. () => this._router.navigate(["List"]),
  234. (error) => alert("Unfortunately we could not find your account.")
  235. );
  236. }
  237. }
  238. ```
  239.  
  240. ## ng6
  241.  
  242. ``` TypeScript
  243. var background = this.page.getViewById("background");
  244. background.backgroundImage = this.page.ios ? "res://bg_login.jpg" : "res://bg_login";
  245. background.animate({
  246. scale: { x: 1.2, y: 1.2 },
  247. duration: 8000
  248. });
  249. ```
  250.  
  251. ## ng7
  252.  
  253. ``` TypeScript
  254. var explosion = require("nativescript-explosionfield");
  255. ```
  256.  
  257. ``` TypeScript
  258. firstTime = true;
  259. submit() {
  260. if (this.firstTime) {
  261. explosion.explode(this.page.getViewById("logo"));
  262. this.firstTime = false;
  263. } else {
  264. explosion.explode(this.page.getViewById("container"));
  265. setTimeout(() => {
  266. explosion.explode(this.page.getViewById("background"));
  267. }, 5000);
  268. }
  269.  
  270. /*this._userService.login(this.user)
  271. .subscribe(
  272. () => this._router.navigate(["List"]),
  273. (error) => alert("Unfortunately we could not find your account.")
  274. );*/
  275. }
  276. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement