|
1 | | -import view = require("ui/core/view"); |
2 | | -import label = require("ui/label"); |
3 | | -import button = require("ui/button"); |
4 | | -import textField = require("ui/text-field"); |
5 | | -import textView = require("ui/text-view"); |
| 1 | +import { EventData, TextBase, TextDecoration } from "ui/text-base"; |
| 2 | +import { Page } from "ui/page"; |
6 | 3 |
|
7 | | -export function changeTextButonTap(args) { |
8 | | - var btnChange = <button.Button>args.object; |
9 | | - var lbl = <label.Label>btnChange.parent.getViewById("Label"); |
10 | | - var btn = <button.Button>btnChange.parent.getViewById("Button"); |
11 | | - var textField = <textField.TextField>btnChange.parent.getViewById("TextField"); |
12 | | - var textView = <textView.TextView>btnChange.parent.getViewById("TextView"); |
13 | | - |
14 | | - if(lbl.text === "Change text") { |
15 | | - lbl.text = btn.text = textField.text = textView.text = "Text changed"; |
16 | | - } else { |
17 | | - lbl.text = btn.text = textField.text = textView.text = "Change text"; |
18 | | - } |
19 | | -} |
20 | | - |
21 | | -export function butonTap(args) { |
22 | | - var btnChange = <view.View>args.object; |
23 | | - var lbl = <label.Label>btnChange.parent.getViewById("Label"); |
24 | | - var btn = <button.Button>btnChange.parent.getViewById("Button"); |
25 | | - var textField = <textField.TextField>btnChange.parent.getViewById("TextField"); |
26 | | - var textView = <textView.TextView>btnChange.parent.getViewById("TextView"); |
| 4 | +const possibleValues = [ |
| 5 | + TextDecoration.NONE, |
| 6 | + TextDecoration.UNDERLINE, |
| 7 | + TextDecoration.LINE_THROUGH, |
| 8 | + TextDecoration.UNDERLINE_LINE_THROUGH |
| 9 | +]; |
27 | 10 |
|
28 | | - if (lbl.style.textDecoration === "none") { |
29 | | - lbl.style.textDecoration = "underline"; |
30 | | - btn.style.textDecoration = "underline"; |
31 | | - textField.style.textDecoration = "underline"; |
32 | | - textView.style.textDecoration = "underline"; |
33 | | - } else if (lbl.style.textDecoration === "underline") { |
34 | | - lbl.style.textDecoration = "line-through"; |
35 | | - btn.style.textDecoration = "line-through"; |
36 | | - textField.style.textDecoration = "line-through"; |
37 | | - textView.style.textDecoration = "line-through"; |
38 | | - } else if (lbl.style.textDecoration === "line-through") { |
39 | | - lbl.style.textDecoration = "line-through underline"; |
40 | | - btn.style.textDecoration = "line-through underline"; |
41 | | - textField.style.textDecoration = "line-through underline"; |
42 | | - textView.style.textDecoration = "line-through underline"; |
43 | | - } else if (lbl.style.textDecoration === "line-through underline") { |
44 | | - lbl.style.textDecoration = "line-through underline none"; |
45 | | - btn.style.textDecoration = "line-through underline none"; |
46 | | - textField.style.textDecoration = "line-through underline none"; |
47 | | - textView.style.textDecoration = "line-through underline none"; |
48 | | - } else if (lbl.style.textDecoration === "line-through underline none") { |
49 | | - lbl.style.textDecoration = "none"; |
50 | | - btn.style.textDecoration = "none"; |
51 | | - textField.style.textDecoration = "none"; |
52 | | - textView.style.textDecoration = "none"; |
53 | | - |
54 | | - if(lbl.text === "Change text") { |
55 | | - lbl.text = btn.text = textField.text = textView.text = "Text changed"; |
56 | | - } else { |
57 | | - lbl.text = btn.text = textField.text = textView.text = "Change text"; |
58 | | - } |
59 | | - } |
| 11 | +export function butonTap(args: EventData) { |
| 12 | + let page = (<TextBase>args.object).page; |
| 13 | + let lbl = <TextBase>page.getViewById("Label"); |
| 14 | + let btn = <TextBase>page.getViewById("Button"); |
| 15 | + let textField = <TextBase>page.getViewById("TextField"); |
| 16 | + let textView = <TextBase>page.getViewById("TextView"); |
| 17 | + |
| 18 | + let currentIndex = possibleValues.indexOf(lbl.textDecoration); |
| 19 | + let newIndex = (currentIndex + 1) % possibleValues.length; |
| 20 | + let newValue = <TextDecoration>possibleValues[newIndex]; |
| 21 | + |
| 22 | + lbl.textDecoration = newValue; |
| 23 | + btn.textDecoration = newValue; |
| 24 | + textField.textDecoration = newValue; |
| 25 | + textView.textDecoration = newValue; |
60 | 26 | } |
0 commit comments