Skip to content

Commit 8330ac0

Browse files
authored
fix(css): widget properties in css didn't work (#6889)
1 parent ddc8601 commit 8330ac0

5 files changed

Lines changed: 66 additions & 2 deletions

File tree

‎tests/app/ui/search-bar/search-bar-tests-native.android.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM
2323
return undefined;
2424
}
2525

26+
export function getNativeTextFieldBackgroundColor(searchBar: searchBarModule.SearchBar): colorModule.Color {
27+
var textView = getTextView(searchBar.android);
28+
29+
if (textView) {
30+
return new colorModule.Color((<android.graphics.drawable.ColorDrawable>textView.getBackground()).getColor());
31+
}
32+
return undefined;
33+
}
34+
2635
export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number {
2736
var textView = getTextView(searchBar.android);
2837

‎tests/app/ui/search-bar/search-bar-tests-native.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import * as searchBarModule from "tns-core-modules/ui/search-bar";
33
import * as colorModule from "tns-core-modules/color";
44

55
export declare function getNativeHintColor(textView: searchBarModule.SearchBar): colorModule.Color;
6+
export declare function getNativeTextFieldBackgroundColor(textView: searchBarModule.SearchBar): colorModule.Color;
67
export declare function getNativeFontSize(searchBar: searchBarModule.SearchBar): number;

‎tests/app/ui/search-bar/search-bar-tests-native.ios.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { getColor } from "../helper";
55
export function getNativeHintColor(searchBar: SearchBar): Color {
66
return (<any>searchBar)._placeholderLabel ? getColor((<any>searchBar)._placeholderLabel.textColor) : undefined;
77
}
8+
9+
export function getNativeTextFieldBackgroundColor(searchBar: SearchBar): Color {
10+
return (<any>searchBar)._textField ? getColor((<any>searchBar)._textField.backgroundColor) : undefined;
11+
}
12+
813
export function getNativeFontSize(searchBar: SearchBar): number {
914
return (<any>searchBar)._textField ? (<any>searchBar)._textField.font.pointSize : undefined;
1015
}

‎tests/app/ui/search-bar/search-bar-tests.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function test_recycling() {
2828
helper.nativeView_recycling_test(() => new searchBarModule.SearchBar());
2929
}
3030

31-
export var testSearchBarHintColorAndroid = function () {
31+
export var testSearchBarHintColor = function () {
3232
helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array<viewModule.View>) {
3333
var searchBar = <searchBarModule.SearchBar>views[0];
3434

@@ -50,6 +50,28 @@ export var testSearchBarHintColorAndroid = function () {
5050
});
5151
};
5252

53+
export var testSearchBarTextFieldBackgroundColor = function () {
54+
helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array<viewModule.View>) {
55+
var searchBar = <searchBarModule.SearchBar>views[0];
56+
57+
searchBar.text = "";
58+
searchBar.hint = "";
59+
60+
var expectedNormalizedValue;
61+
var actualValue;
62+
63+
searchBar.textFieldBackgroundColor = new colorModule.Color("blue");
64+
expectedNormalizedValue = "#0000FF"; // blue
65+
actualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex;
66+
TKUnit.assert(actualValue === expectedNormalizedValue, "Actual: " + actualValue + "; Expected: " + expectedNormalizedValue);
67+
68+
searchBar.textFieldBackgroundColor = new colorModule.Color("red");
69+
expectedNormalizedValue = "#FF0000"; // red
70+
actualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex;
71+
TKUnit.assert(actualValue === expectedNormalizedValue, "Actual: " + actualValue + "; Expected: " + expectedNormalizedValue);
72+
});
73+
};
74+
5375
export var testSearchBarFontSize = function () {
5476
helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array<viewModule.View>) {
5577
var searchBar = <searchBarModule.SearchBar>views[0];
@@ -66,6 +88,32 @@ export var testSearchBarFontSize = function () {
6688
});
6789
};
6890

91+
export var testSearchBarPropertiesWithCSS = function () {
92+
helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array<viewModule.View>) {
93+
var searchBar = <searchBarModule.SearchBar>views[0];
94+
95+
const expectedHintColor = "#0000FF"; // blue
96+
const expectedTextFieldBackgroundColor = "#FF0000"; // red
97+
const expectedFontSize = 30;
98+
99+
const hintColorActualValue = searchBarTestsNative.getNativeHintColor(searchBar).hex;
100+
const textFieldBackgroundColorActualValue = searchBarTestsNative.getNativeTextFieldBackgroundColor(searchBar).hex;
101+
const fontSizeActualValue = searchBarTestsNative.getNativeFontSize(searchBar);
102+
103+
TKUnit.assert(hintColorActualValue === expectedHintColor, "HintColor - Actual: " + hintColorActualValue + "; Expected: " + expectedHintColor);
104+
TKUnit.assert(expectedTextFieldBackgroundColor === textFieldBackgroundColorActualValue, "Text Background Color - Actual: " + textFieldBackgroundColorActualValue + "; Expected: " + expectedTextFieldBackgroundColor);
105+
TKUnit.assertAreClose(expectedFontSize, fontSizeActualValue, 0.2, "Font Size - Actual: " + fontSizeActualValue + "; Expected: " + expectedFontSize);
106+
}, { pageCss: `
107+
SearchBar {
108+
text: test;
109+
hint: test;
110+
text-field-hint-color: blue;
111+
text-field-background-color: red;
112+
font-size: 30;
113+
}
114+
`});
115+
};
116+
69117
export function test_DummyTestForSnippetOnly() {
70118
// >> article-searching
71119
var searchBar = new searchBarModule.SearchBar();

‎tns-core-modules/ui/styling/style-scope.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ export class CssState {
481481
if (property in this.view.style) {
482482
this.view.style[`css:${property}`] = value;
483483
} else {
484-
this.view[property] = value;
484+
const camelCasedProperty = property.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
485+
this.view[camelCasedProperty] = value;
485486
}
486487
} catch (e) {
487488
traceWrite(`Failed to apply property [${property}] with value [${value}] to ${this.view}. ${e}`, traceCategories.Error, traceMessageType.error);

0 commit comments

Comments
 (0)