From 3fb4b59b875be2e1b7600b791fd2c691b12a101a Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 28 Aug 2015 10:46:35 +0300 Subject: [PATCH 1/4] setStyle implementation + test --- apps/tests/ui/view/view-tests-common.ts | 14 ++++++++++++++ ui/core/view-common.ts | 6 ++++++ ui/core/view.d.ts | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index ccb3568af..56421f56d 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -613,6 +613,20 @@ export var testIsVisible = function () { }); } +export var testSetStyle = function () { + var lbl = new label.Label(); + + var expectedColor = "#ff0000"; + var expectedBackgroundColor = "#ff0000"; + + lbl.setStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); + + helper.buildUIAndRunTest(lbl, function (views: Array) { + TKUnit.assert(lbl.color.hex === expectedColor, "Actual: " + lbl.color.hex + "; Expected: " + expectedColor); + TKUnit.assert(lbl.backgroundColor.hex === expectedBackgroundColor, "Actual: " + lbl.backgroundColor.hex + "; Expected: " + expectedBackgroundColor); + }); +} + export var testBorderWidth = function () { helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { var lbl = views[0]; diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index eb02cd8d0..788fe65d0 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -923,6 +923,12 @@ export class View extends proxy.ProxyObject implements definition.View { return false; } + public setStyle(style: string): void { + if (types.isString(style)) { + this._applyInlineStyle(style); + } + } + public _updateLayout() { // needed for iOS. } diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index b2fbfdc5d..102d31440 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -356,6 +356,12 @@ declare module "ui/core/view" { */ public focus(): boolean; + /** + * Sets in-line CSS string as style. + * @param style - In-line CSS string. + */ + public setStyle(style: string) : void; + public getGestureObservers(type: gestures.GestureTypes): Array; /** From c12bb8366bf999c9cb38f7b5ffc29b47d6530fab Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 28 Aug 2015 11:11:28 +0300 Subject: [PATCH 2/4] test improved --- apps/tests/ui/view/view-tests-common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index 56421f56d..756442bd5 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -622,8 +622,8 @@ export var testSetStyle = function () { lbl.setStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); helper.buildUIAndRunTest(lbl, function (views: Array) { - TKUnit.assert(lbl.color.hex === expectedColor, "Actual: " + lbl.color.hex + "; Expected: " + expectedColor); - TKUnit.assert(lbl.backgroundColor.hex === expectedBackgroundColor, "Actual: " + lbl.backgroundColor.hex + "; Expected: " + expectedBackgroundColor); + TKUnit.assertEqual(lbl.color.hex, expectedColor); + TKUnit.assertEqual(lbl.backgroundColor.hex, expectedBackgroundColor); }); } From 035e3816731d963c4562475f0a8ac6478d870a5f Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 28 Aug 2015 11:16:26 +0300 Subject: [PATCH 3/4] throw error if not string --- ui/core/view-common.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index 788fe65d0..19c6b76c5 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -924,9 +924,11 @@ export class View extends proxy.ProxyObject implements definition.View { } public setStyle(style: string): void { - if (types.isString(style)) { - this._applyInlineStyle(style); + if (!types.isString(style)) { + throw new Error("Parameter should be valid CSS string!"); } + + this._applyInlineStyle(style); } public _updateLayout() { From 0aec9882512a6d0e7412c956a89f40957e64e708 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 28 Aug 2015 11:18:25 +0300 Subject: [PATCH 4/4] setStyle renamed to setInlineStyle --- apps/tests/ui/view/view-tests-common.ts | 4 ++-- ui/core/view-common.ts | 2 +- ui/core/view.d.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index 756442bd5..74134f0b0 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -613,13 +613,13 @@ export var testIsVisible = function () { }); } -export var testSetStyle = function () { +export var testSetInlineStyle = function () { var lbl = new label.Label(); var expectedColor = "#ff0000"; var expectedBackgroundColor = "#ff0000"; - lbl.setStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); + lbl.setInlineStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); helper.buildUIAndRunTest(lbl, function (views: Array) { TKUnit.assertEqual(lbl.color.hex, expectedColor); diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index 19c6b76c5..0306dc9c9 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -923,7 +923,7 @@ export class View extends proxy.ProxyObject implements definition.View { return false; } - public setStyle(style: string): void { + public setInlineStyle(style: string): void { if (!types.isString(style)) { throw new Error("Parameter should be valid CSS string!"); } diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index 102d31440..b2eab2809 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -360,7 +360,7 @@ declare module "ui/core/view" { * Sets in-line CSS string as style. * @param style - In-line CSS string. */ - public setStyle(style: string) : void; + public setInlineStyle(style: string) : void; public getGestureObservers(type: gestures.GestureTypes): Array;