font-size CSS support for search-bar + test

This commit is contained in:
Vladimir Enchev
2015-08-12 15:19:04 +03:00
parent 1c76e9c64b
commit 2d07eb9dd0
7 changed files with 122 additions and 1 deletions

View File

@@ -475,6 +475,45 @@ export class SearchBarStyler implements definition.stylers.Styler {
SearchBarStyler._changeSearchViewTextColor(bar, nativeValue);
}
// font
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
var bar = <android.widget.SearchView>view.android;
var textView = SearchBarStyler._getSearchViewTextView(bar);
var fontValue = <font.Font>newValue;
var typeface = fontValue.getAndroidTypeface();
if (typeface) {
textView.setTypeface(typeface);
}
else {
textView.setTypeface(nativeValue.typeface);
}
if (fontValue.fontSize) {
textView.setTextSize(fontValue.fontSize);
}
else {
textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
}
}
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
var bar = <android.widget.SearchView>view.android;
var textView = SearchBarStyler._getSearchViewTextView(bar);
textView.setTypeface(nativeValue.typeface);
textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, nativeValue.size);
}
private static getNativeFontInternalValue(view: view.View): any {
var bar = <android.widget.SearchView>view.android;
var textView = SearchBarStyler._getSearchViewTextView(bar);
return {
typeface: textView.getTypeface(),
size: textView.getTextSize()
};
}
public static registerHandlers() {
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
SearchBarStyler.setBackgroundColorProperty,
@@ -485,6 +524,11 @@ export class SearchBarStyler implements definition.stylers.Styler {
SearchBarStyler.setColorProperty,
SearchBarStyler.resetColorProperty,
SearchBarStyler.getColorProperty), "SearchBar");
style.registerHandler(style.fontInternalProperty, new stylersCommon.StylePropertyChangedHandler(
SearchBarStyler.setFontInternalProperty,
SearchBarStyler.resetFontInternalProperty,
SearchBarStyler.getNativeFontInternalValue), "SearchBar");
}
private static _getSearchViewTextView(bar: android.widget.SearchView): android.widget.TextView {

View File

@@ -437,6 +437,33 @@ export class SearchBarStyler implements definition.stylers.Styler {
}
}
// font
private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) {
var bar = <UISearchBar>view.ios;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) {
sf.font = (<font.Font>newValue).getUIFont(newValue);
}
}
private static resetFontInternalProperty(view: view.View, nativeValue: any) {
var bar = <UISearchBar>view.ios;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) {
sf.font = nativeValue;
}
}
private static getNativeFontInternalValue(view: view.View): any {
var bar = <UISearchBar>view.ios;
var sf = <UITextField>bar.valueForKey("_searchField");
if (sf) {
return sf.font;
}
return undefined;
}
public static registerHandlers() {
style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler(
SearchBarStyler.setBackgroundColorProperty,
@@ -447,6 +474,11 @@ export class SearchBarStyler implements definition.stylers.Styler {
SearchBarStyler.setColorProperty,
SearchBarStyler.resetColorProperty,
SearchBarStyler.getColorProperty), "SearchBar");
style.registerHandler(style.fontInternalProperty, new stylersCommon.StylePropertyChangedHandler(
SearchBarStyler.setFontInternalProperty,
SearchBarStyler.resetFontInternalProperty,
SearchBarStyler.getNativeFontInternalValue), "SearchBar");
}
}