From 2d984022ef83167866540bff2ddf97d0f91eea01 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Tue, 10 Mar 2015 10:10:23 +0200 Subject: [PATCH] stylers fixed --- ui/styling/stylers.android.ts | 38 +++++++++++++++++++++++++++++------ ui/styling/stylers.ios.ts | 32 +++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/ui/styling/stylers.android.ts b/ui/styling/stylers.android.ts index fd96070dd..058113cc1 100644 --- a/ui/styling/stylers.android.ts +++ b/ui/styling/stylers.android.ts @@ -241,6 +241,11 @@ export class SegmentedBarStyler implements definition.stylers.Styler { export class SearchBarStyler implements definition.stylers.Styler { + private static getBackgroundColorProperty(view: view.View): any { + var bar = view.android; + return bar.getDrawingCacheBackgroundColor(); + } + private static setBackgroundColorProperty(view: view.View, newValue: any) { var bar = view.android; bar.setBackgroundColor(newValue); @@ -253,6 +258,17 @@ export class SearchBarStyler implements definition.stylers.Styler { SearchBarStyler._changeSearchViewPlateBackgroundColor(bar, nativeValue); } + private static getColorProperty(view: view.View): any { + var bar = view.android; + var textView = SearchBarStyler._getSearchViewTextView(bar); + + if (textView) { + return textView.getCurrentTextColor(); + } + + return undefined; + } + private static setColorProperty(view: view.View, newValue: any) { var bar = view.android; SearchBarStyler._changeSearchViewTextColor(bar, newValue); @@ -266,23 +282,33 @@ export class SearchBarStyler implements definition.stylers.Styler { public static registerHandlers() { style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler( SearchBarStyler.setBackgroundColorProperty, - SearchBarStyler.resetBackgroundColorProperty), "SearchBar"); + SearchBarStyler.resetBackgroundColorProperty, + SearchBarStyler.getBackgroundColorProperty), "SearchBar"); style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler( SearchBarStyler.setColorProperty, - SearchBarStyler.resetColorProperty), "SearchBar"); + SearchBarStyler.resetColorProperty, + SearchBarStyler.getColorProperty), "SearchBar"); + } + + private static _getSearchViewTextView(bar: android.widget.SearchView): android.widget.TextView { + var id = bar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); + return bar.findViewById(id); } private static _changeSearchViewTextColor(bar: android.widget.SearchView, color: number) { - var id = bar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null); - var textView = bar.findViewById(id); - textView.setTextColor(color); + var textView = SearchBarStyler._getSearchViewTextView(bar); + if (textView) { + textView.setTextColor(color); + } } private static _changeSearchViewPlateBackgroundColor(bar: android.widget.SearchView, color: number) { var id = bar.getContext().getResources().getIdentifier("android:id/search_plate", null, null); var textView = bar.findViewById(id); - textView.setBackgroundColor(color); + if (textView) { + textView.setBackgroundColor(color); + } } } diff --git a/ui/styling/stylers.ios.ts b/ui/styling/stylers.ios.ts index 01f74799c..029b9b970 100644 --- a/ui/styling/stylers.ios.ts +++ b/ui/styling/stylers.ios.ts @@ -496,31 +496,55 @@ export class SearchBarStyler implements definition.stylers.Styler { bar.barTintColor = newValue; } + private static getBackgroundColorProperty(view: view.View): any { + var bar = view.ios; + return bar.barTintColor; + } + private static resetBackgroundColorProperty(view: view.View, nativeValue: any) { var bar = view.ios; bar.barTintColor = nativeValue; } + private static getColorProperty(view: view.View): any { + var bar = view.ios; + + var sf = bar.valueForKey("_searchField"); + if (sf) { + return sf.textColor; + } + + return undefined; + } + private static setColorProperty(view: view.View, newValue: any) { var bar = view.ios; - (bar.valueForKey("_searchField")).textColor = newValue; + var sf = bar.valueForKey("_searchField"); + if (sf) { + sf.textColor = newValue; + } } private static resetColorProperty(view: view.View, nativeValue: any) { var bar = view.ios; - (bar.valueForKey("_searchField")).textColor = nativeValue; + var sf = bar.valueForKey("_searchField"); + if (sf) { + sf.textColor = nativeValue; + } } public static registerHandlers() { style.registerHandler(style.backgroundColorProperty, new stylersCommon.StylePropertyChangedHandler( SearchBarStyler.setBackgroundColorProperty, - SearchBarStyler.resetBackgroundColorProperty), "SearchBar"); + SearchBarStyler.resetBackgroundColorProperty, + SearchBarStyler.getBackgroundColorProperty), "SearchBar"); style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler( SearchBarStyler.setColorProperty, - SearchBarStyler.resetColorProperty), "SearchBar"); + SearchBarStyler.resetColorProperty, + SearchBarStyler.getColorProperty), "SearchBar"); } }