diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index ee277bb4c..dda79ba63 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -144,6 +144,9 @@ + + + @@ -1929,7 +1932,7 @@ False - + \ No newline at end of file diff --git a/apps/tests/ui/search-bar/search-bar-tests-native.android.ts b/apps/tests/ui/search-bar/search-bar-tests-native.android.ts index 920166053..a40519241 100644 --- a/apps/tests/ui/search-bar/search-bar-tests-native.android.ts +++ b/apps/tests/ui/search-bar/search-bar-tests-native.android.ts @@ -1,5 +1,6 @@ import colorModule = require("color"); import searchBarModule = require("ui/search-bar"); +import utils = require("utils/utils"); function getTextView(bar: android.widget.SearchView): android.widget.TextView { if (bar) { @@ -20,3 +21,12 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM } return undefined; } + +export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number { + var textView = getTextView(searchBar.android); + + if (textView) { + return textView.getTextSize() / utils.layout.getDisplayDensity(); + } + return undefined; +} \ No newline at end of file diff --git a/apps/tests/ui/search-bar/search-bar-tests-native.d.ts b/apps/tests/ui/search-bar/search-bar-tests-native.d.ts index b825413cd..268a1587e 100644 --- a/apps/tests/ui/search-bar/search-bar-tests-native.d.ts +++ b/apps/tests/ui/search-bar/search-bar-tests-native.d.ts @@ -3,3 +3,4 @@ import searchBarModule = require("ui/search-bar"); import colorModule = require("color"); export declare function getNativeHintColor(textView: searchBarModule.SearchBar): colorModule.Color; +export declare function getNativeFontSize(searchBar: searchBarModule.SearchBar): number; \ No newline at end of file diff --git a/apps/tests/ui/search-bar/search-bar-tests-native.ios.ts b/apps/tests/ui/search-bar/search-bar-tests-native.ios.ts index 30256c94f..4ad9e380b 100644 --- a/apps/tests/ui/search-bar/search-bar-tests-native.ios.ts +++ b/apps/tests/ui/search-bar/search-bar-tests-native.ios.ts @@ -5,3 +5,13 @@ export function getNativeHintColor(searchBar: searchBarModule.SearchBar): colorM // TODO: This test needs to be created return undefined; } +export function getNativeFontSize(searchBar: searchBarModule.SearchBar): number { + var bar = searchBar.ios; + var sf = bar.valueForKey("_searchField"); + if (sf) { + return sf.font.pointSize; + } + + return undefined; +} + diff --git a/apps/tests/ui/search-bar/search-bar-tests.ts b/apps/tests/ui/search-bar/search-bar-tests.ts index ce076e461..c0a20e54f 100644 --- a/apps/tests/ui/search-bar/search-bar-tests.ts +++ b/apps/tests/ui/search-bar/search-bar-tests.ts @@ -58,6 +58,27 @@ export var testSearchBarHintColorAndroid = function () { }); }; +export var testSearchBarFontSize = function () { + helper.buildUIAndRunTest(_createSearchBarFunc(), function (views: Array) { + var searchBar = views[0]; + + // TODO: create IOS test once IOS support is working + if (!searchBar.android) { + return; + } + + searchBar.text = ""; + searchBar.hint = "hint color test"; + + var expectedValue = 30; + var actualValue; + + searchBar.style.fontSize = expectedValue; + actualValue = searchBarTestsNative.getNativeFontSize(searchBar); + TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); + }); +}; + export function test_DummyTestForSnippetOnly() { // // ### Searching diff --git a/ui/styling/stylers.android.ts b/ui/styling/stylers.android.ts index 685e01360..842e4ff19 100644 --- a/ui/styling/stylers.android.ts +++ b/ui/styling/stylers.android.ts @@ -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 = view.android; + var textView = SearchBarStyler._getSearchViewTextView(bar); + + var fontValue = 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 = 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 = 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 { diff --git a/ui/styling/stylers.ios.ts b/ui/styling/stylers.ios.ts index 1fd3a3aea..1851888d8 100644 --- a/ui/styling/stylers.ios.ts +++ b/ui/styling/stylers.ios.ts @@ -437,6 +437,33 @@ export class SearchBarStyler implements definition.stylers.Styler { } } + // font + private static setFontInternalProperty(view: view.View, newValue: any, nativeValue: any) { + var bar = view.ios; + var sf = bar.valueForKey("_searchField"); + if (sf) { + sf.font = (newValue).getUIFont(newValue); + } + } + + private static resetFontInternalProperty(view: view.View, nativeValue: any) { + var bar = view.ios; + var sf = bar.valueForKey("_searchField"); + if (sf) { + sf.font = nativeValue; + } + } + + private static getNativeFontInternalValue(view: view.View): any { + var bar = view.ios; + var sf = 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"); } }