Resolved Issue #754: The backgroundColor of a Label is not animatable in iOS.

This commit is contained in:
Rossen Hristov
2015-11-25 11:46:34 +02:00
parent df9f9978c2
commit b702840cbf
8 changed files with 159 additions and 53 deletions

View File

@@ -1,5 +1,7 @@
import labelModule = require("ui/label");
import enums = require("ui/enums");
import colorModule = require("color");
import background = require("ui/styling/background");
export function getNativeTextAlignment(label: labelModule.Label): string {
var gravity = label.android.getGravity();
@@ -17,4 +19,14 @@ export function getNativeTextAlignment(label: labelModule.Label): string {
}
return "unexpected value";
}
export function getNativeBackgroundColor(label: labelModule.Label): colorModule.Color {
var bkg = <any>label.android.getBackground();
if (bkg instanceof background.ad.BorderDrawable) {
return (<background.ad.BorderDrawable>bkg).background.color;
}
else {
return new colorModule.Color(bkg.backgroundColor)
}
}

View File

@@ -1,4 +1,7 @@
//@private
import labelModule = require("ui/label");
import colorModule = require("color");
export declare function getNativeTextAlignment(label: labelModule.Label): string;
export declare function getNativeTextAlignment(label: labelModule.Label): string;
export declare function getNativeBackgroundColor(label: labelModule.Label): colorModule.Color;

View File

@@ -1,5 +1,7 @@
import labelModule = require("ui/label");
import enums = require("ui/enums");
import colorModule = require("color");
import utilsModule = require("utils/utils");
export function getNativeTextAlignment(label: labelModule.Label): string {
switch (label.ios.textAlignment) {
@@ -16,4 +18,13 @@ export function getNativeTextAlignment(label: labelModule.Label): string {
return "unexpected value";
break;
}
}
}
export function getNativeBackgroundColor(label: labelModule.Label): colorModule.Color {
var layer = (<UILabel>label.ios).layer;
if (!layer || !layer.backgroundColor) {
return undefined;
}
var uiColor = UIColor.colorWithCGColor(layer.backgroundColor);
return utilsModule.ios.getColor(uiColor);
}

View File

@@ -1,5 +1,6 @@
import TKUnit = require("../../TKUnit");
import testModule = require("../../ui-test");
import styling = require("ui/styling");
// <snippet module="ui/label" title="Label">
// # Label
@@ -88,6 +89,29 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
}
public test_Set_BackgroundColor_TNS() {
var label = this.testView;
var expectedValue = new colorModule.Color("Red");
label.backgroundColor = expectedValue;
var actual = label.style._getValue(styling.properties.backgroundColorProperty);
TKUnit.assertEqual(actual, expectedValue, "BackgroundColor not equal");
}
public test_Set_BackgroundColor_Native() {
var testLabel = this.testView;
var expectedValue = new colorModule.Color("Red");
testLabel.backgroundColor = expectedValue;
if (testLabel.android) {
this.waitUntilTestElementIsLoaded();
}
var actualNative = labelTestsNative.getNativeBackgroundColor(testLabel);
TKUnit.assertEqual(actualNative, expectedValue);
}
public test_measuredWidth_is_not_clipped() {
var label = this.testView;
label.horizontalAlignment = "left";
@@ -238,7 +262,9 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
expColor = new colorModule.Color(color);
TKUnit.assertEqual(normalColor.hex, expColor.hex);
actualBackgroundColor = utils.ios.getColor(testLabel.ios.backgroundColor);
var cgColor = (<UILabel>testLabel.ios).layer.backgroundColor;
var uiColor = UIColor.colorWithCGColor(cgColor);
actualBackgroundColor = utils.ios.getColor(uiColor);
expBackgroundColor = new colorModule.Color(backgroundColor);
TKUnit.assertEqual(actualBackgroundColor.hex, expBackgroundColor.hex);
}

View File

@@ -495,7 +495,7 @@ var changeIdOrClassTestCss =
"#myButton { background-color: #444444 } " +
"#myButtonTwo { background-color: #555555 } ";
export function test_styles_are_updated_when_cssCalss_is_set() {
export function test_styles_are_updated_when_cssClass_is_set() {
var testStack = new stackModule.StackLayout();
var btn = new buttonModule.Button();
var btn2 = new buttonModule.Button();
@@ -515,7 +515,7 @@ export function test_styles_are_updated_when_cssCalss_is_set() {
helper.buildUIAndRunTest(testStack, testFunc, changeIdOrClassTestCss);
}
export function test_styles_are_updated_when_cssCalss_is_changed() {
export function test_styles_are_updated_when_cssClass_is_changed() {
var testStack = new stackModule.StackLayout();
var btn = new buttonModule.Button();
btn.className = "button-class";
@@ -536,7 +536,7 @@ export function test_styles_are_updated_when_cssCalss_is_changed() {
helper.buildUIAndRunTest(testStack, testFunc, changeIdOrClassTestCss);
}
export function test_styles_are_updated_when_cssCalss_is_cleared() {
export function test_styles_are_updated_when_cssClass_is_cleared() {
var testStack = new stackModule.StackLayout();
var btn = new buttonModule.Button();
btn.className = "button-class";

View File

@@ -16,6 +16,12 @@ export function checkNativeBorderColor(v: view.View): boolean {
}
export function checkNativeBackgroundColor(v: view.View): boolean {
if (v.ios instanceof UILabel) {
var cgColor1 = (<UILabel>v.ios).layer.backgroundColor;
var cgColor2 = (<UIColor>v.backgroundColor.ios).CGColor;
return v.backgroundColor && CGColorEqualToColor(cgColor1, cgColor2);
}
return v.backgroundColor && (<UIView>v.ios).backgroundColor.isEqual(v.backgroundColor.ios);
}