Merge pull request #2611 from NativeScript/issue-2601

Fix: Text color of the Button not applied, when text-transform has be…
This commit is contained in:
Rossen Hristov
2016-08-23 10:00:06 +03:00
committed by GitHub
7 changed files with 59 additions and 11 deletions

10
apps/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,10 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}

View File

@@ -25,6 +25,7 @@ export function pageLoaded(args: EventData) {
examples.set("clipPath", "css/clip-path");
examples.set("padding", "css/padding");
examples.set("label-background-image", "css/label-background-image");
examples.set("transform-decoration-color", "css/transform-decoration-color");
let viewModel = new SubMianPageViewModel(wrapLayout, examples);
page.bindingContext = viewModel;

View File

@@ -0,0 +1,8 @@
Label, Button, TextField, TextView {
font-size: 12;
text-align: left;
}
TextView {
margin-bottom: 10;
}

View File

@@ -0,0 +1,23 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<StackLayout>
<Label text="Label red" style="color: red;"/>
<Button text="Button red" style="color: red;"/>
<TextField text="TextField red" style="color: red;"/>
<TextView text="TextView red" style="color: red;"/>
<Label text="Label uppercase red" style="text-transform: uppercase; color: red;"/>
<Button text="Button uppercase red" style="text-transform: uppercase; color: red;"/>
<TextField text="TextField uppercase red" style="text-transform: uppercase; color: red;"/>
<TextView text="TextView uppercase red" style="text-transform: uppercase; color: red;"/>
<Label text="Label underline line-through blue" style="text-decoration: underline line-through; color: blue;"/>
<Button text="Button underline line-through blue" style="text-decoration: underline line-through; color: blue;"/>
<TextField text="TextField underline line-through blue" style="text-decoration: underline line-through; color: blue;"/>
<TextView text="TextView underline line-through blue" style="text-decoration: underline line-through; color: blue;"/>
<Label text="Label uppercase underline line-through green" style="text-transform: uppercase; text-decoration: underline line-through; color: green;"/>
<Button text="Button uppercase underline line-through green" style="text-transform: uppercase; text-decoration: underline line-through; color: green;"/>
<TextField text="TextField uppercase underline line-through green" style="text-transform: uppercase; text-decoration: underline line-through; color: green;"/>
<TextView text="TextView uppercase underline line-through green" style="text-transform: uppercase; text-decoration: underline line-through; color: green;"/>
</StackLayout>
</Page>

View File

@@ -5,11 +5,11 @@
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.apps",
"tns-android": {
"version": "2.1.1"
},
"tns-ios": {
"version": "2.1.1"
"version": "2.2.1"
},
"tns-android": {
"version": "2.2.0"
}
},
"dependencies": {

View File

@@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.tests",
"tns-ios": {
"version": "2.1.1"
"version": "2.2.1"
},
"tns-android": {
"version": "2.1.1"
"version": "2.2.0"
}
},
"dependencies": {

View File

@@ -279,11 +279,10 @@ export class ButtonStyler implements style.Styler {
let attributes = new Array();
let range = { location: 0, length: source.length };
var decorationValues = (decoration + "").split(" ");
let decorationValues = (decoration + "").split(" ");
let dict = new Map<string, number>();
if (decorationValues.indexOf(enums.TextDecoration.none) === -1 || hasLetterSpacing) {
let dict = new Map<string, number>();
if (decorationValues.indexOf(enums.TextDecoration.underline) !== -1) {
dict.set(NSUnderlineStyleAttributeName, NSUnderlineStyle.NSUnderlineStyleSingle);
}
@@ -295,14 +294,21 @@ export class ButtonStyler implements style.Styler {
if (hasLetterSpacing) {
dict.set(NSKernAttributeName, letterSpacing * button.ios.font.pointSize);
}
}
let buttonColor = button.style.color;
if (buttonColor){
dict.set(NSForegroundColorAttributeName, buttonColor.ios);
}
if (dict.size > 0){
attributes.push({ attrs: dict, range: NSValue.valueWithRange(range) });
}
source = utils.ios.getTransformedText(button, source, transform);
let result = NSMutableAttributedString.alloc().initWithString(source);
if (attributes.length > 0) {
let result = NSMutableAttributedString.alloc().initWithString(source);
for (let i = 0; i < attributes.length; i++) {
result.setAttributesRange(attributes[i]["attrs"], attributes[i]["range"].rangeValue);
}
@@ -310,7 +316,7 @@ export class ButtonStyler implements style.Styler {
button.ios.setAttributedTitleForState(result, UIControlState.UIControlStateNormal);
}
else {
button.ios.setAttributedTitleForState(NSMutableAttributedString.alloc().initWithString(source), UIControlState.UIControlStateNormal);
button.ios.setAttributedTitleForState(result, UIControlState.UIControlStateNormal);
button.ios.setTitleForState(source, UIControlState.UIControlStateNormal);
}
}