Fixed: getViewById, TextDecoration

This commit is contained in:
Rossen Hristov
2016-12-15 13:20:25 +02:00
parent 8d573e0304
commit 51e448aa10
16 changed files with 170 additions and 214 deletions

View File

@@ -1,60 +1,26 @@
import view = require("ui/core/view");
import label = require("ui/label");
import button = require("ui/button");
import textField = require("ui/text-field");
import textView = require("ui/text-view");
import { EventData, TextBase, TextDecoration } from "ui/text-base";
import { Page } from "ui/page";
export function changeTextButonTap(args) {
var btnChange = <button.Button>args.object;
var lbl = <label.Label>btnChange.parent.getViewById("Label");
var btn = <button.Button>btnChange.parent.getViewById("Button");
var textField = <textField.TextField>btnChange.parent.getViewById("TextField");
var textView = <textView.TextView>btnChange.parent.getViewById("TextView");
const possibleValues = [
TextDecoration.NONE,
TextDecoration.UNDERLINE,
TextDecoration.LINE_THROUGH,
TextDecoration.UNDERLINE_LINE_THROUGH
];
export function butonTap(args: EventData) {
let page = (<TextBase>args.object).page;
let lbl = <TextBase>page.getViewById("Label");
let btn = <TextBase>page.getViewById("Button");
let textField = <TextBase>page.getViewById("TextField");
let textView = <TextBase>page.getViewById("TextView");
if(lbl.text === "Change text") {
lbl.text = btn.text = textField.text = textView.text = "Text changed";
} else {
lbl.text = btn.text = textField.text = textView.text = "Change text";
}
}
export function butonTap(args) {
var btnChange = <view.View>args.object;
var lbl = <label.Label>btnChange.parent.getViewById("Label");
var btn = <button.Button>btnChange.parent.getViewById("Button");
var textField = <textField.TextField>btnChange.parent.getViewById("TextField");
var textView = <textView.TextView>btnChange.parent.getViewById("TextView");
if (lbl.style.textDecoration === "none") {
lbl.style.textDecoration = "underline";
btn.style.textDecoration = "underline";
textField.style.textDecoration = "underline";
textView.style.textDecoration = "underline";
} else if (lbl.style.textDecoration === "underline") {
lbl.style.textDecoration = "line-through";
btn.style.textDecoration = "line-through";
textField.style.textDecoration = "line-through";
textView.style.textDecoration = "line-through";
} else if (lbl.style.textDecoration === "line-through") {
lbl.style.textDecoration = "line-through underline";
btn.style.textDecoration = "line-through underline";
textField.style.textDecoration = "line-through underline";
textView.style.textDecoration = "line-through underline";
} else if (lbl.style.textDecoration === "line-through underline") {
lbl.style.textDecoration = "line-through underline none";
btn.style.textDecoration = "line-through underline none";
textField.style.textDecoration = "line-through underline none";
textView.style.textDecoration = "line-through underline none";
} else if (lbl.style.textDecoration === "line-through underline none") {
lbl.style.textDecoration = "none";
btn.style.textDecoration = "none";
textField.style.textDecoration = "none";
textView.style.textDecoration = "none";
if(lbl.text === "Change text") {
lbl.text = btn.text = textField.text = textView.text = "Text changed";
} else {
lbl.text = btn.text = textField.text = textView.text = "Change text";
}
}
let currentIndex = possibleValues.indexOf(lbl.textDecoration);
let newIndex = (currentIndex + 1) % possibleValues.length;
let newValue = <TextDecoration>possibleValues[newIndex];
lbl.textDecoration = newValue;
btn.textDecoration = newValue;
textField.textDecoration = newValue;
textView.textDecoration = newValue;
}

View File

@@ -1,36 +1,9 @@
<Page >
<Page>
<StackLayout>
<!--<Button id="ChangeText" automationText="Change text" text="Change text" tap="changeTextButonTap" />-->
<Button id="Change" automationText="Change" text="Change" tap="butonTap" />
<Label id="Label" automationText="Label" text="Label" style.textDecoration="none" />
<Button id="Button" automationText="Button" text="Button" style.textDecoration="none" />
<TextField id="TextField" automationText="TextField" text="TextField" style.textDecoration="none" />
<TextView id="TextView" automationText="TextView" text="TextView" style.textDecoration="none" />
<!--
<Label text="Label" style="text-decoration:none" />
<Label text="Label" style="text-decoration:underline" />
<Label text="Label" style="text-decoration:line-through" />
<Label text="Label" style="text-decoration:line-through underline" />
<Label text="Label" style="text-decoration:line-through underline none" />
<TextField text="TextField" style="text-decoration:none" />
<TextField text="TextField" style="text-decoration:underline" />
<TextField text="TextField" style="text-decoration:line-through" />
<TextField text="TextField" style="text-decoration:underline line-through" />
<TextField text="TextField" style="text-decoration:underline line-through none" />
<TextView text="TextView" style="text-decoration:none" />
<TextView text="TextView" style="text-decoration:underline" />
<TextView text="TextView" style="text-decoration:line-through" />
<TextView text="TextView" style="text-decoration:line-through underline" />
<TextView text="TextView" style="text-decoration:line-through underline none" />
<Button text="Button" style="text-decoration:none" />
<Button text="Button" style="text-decoration:underline" />
<Button text="Button" style="text-decoration:line-through" />
<Button text="Button" style="text-decoration:underline line-through" />
<Button text="Button" style="text-decoration:underline line-through none" />
-->
<Label id="Label" automationText="Label" text="Label" textDecoration="none" />
<Button id="Button" automationText="Button" text="Button" textDecoration="none" />
<TextField id="TextField" automationText="TextField" text="TextField" textDecoration="none" />
<TextView id="TextView" automationText="TextView" text="TextView" textDecoration="none" />
</StackLayout>
</Page>

View File

@@ -35,30 +35,15 @@ export function butonTap(args) {
btn.style.textTransform = "uppercase";
textField.style.textTransform = "uppercase";
textView.style.textTransform = "uppercase";
} else if (lbl.style.textTransform === "uppercase" && lbl.style.textDecoration !== "line-through underline") {
} else if (lbl.style.textTransform === "uppercase") {
lbl.style.textTransform = "lowercase";
btn.style.textTransform = "lowercase";
textField.style.textTransform = "lowercase";
textView.style.textTransform = "lowercase";
} else if (lbl.style.textTransform === "lowercase") {
// lbl.style.textTransform = "uppercase";
// btn.style.textTransform = "uppercase";
// textField.style.textTransform = "uppercase";
// textView.style.textTransform = "uppercase";
// lbl.style.textDecoration = "line-through underline";
// btn.style.textDecoration = "line-through underline";
// textField.style.textDecoration = "line-through underline";
// textView.style.textDecoration = "line-through underline";
//} else if (lbl.style.textTransform === "uppercase" && lbl.style.textDecoration === "line-through underline") {
lbl.style.textTransform = "none";
btn.style.textTransform = "none";
textField.style.textTransform = "none";
textView.style.textTransform = "none";
//lbl.style.textDecoration = "none";
//btn.style.textDecoration = "none";
//textField.style.textDecoration = "none";
//textView.style.textDecoration = "none";
}
}