mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Adding Search Hint text color; since this is not accessible from the standard style/theming xml files.
Added Tests so that it will verify the search bar color is changing.
This commit is contained in:
@@ -9,6 +9,9 @@ export class SearchBar extends view.View implements definition.SearchBar {
|
||||
public static clearEvent = "clear";
|
||||
|
||||
public static textFieldBackgroundColorProperty = new dependencyObservable.Property("textFieldBackgroundColor", "SearchBar", new proxy.PropertyMetadata(undefined))
|
||||
|
||||
public static textFieldHintColorProperty = new dependencyObservable.Property("textFieldHintColor", "SearchBar", new proxy.PropertyMetadata(undefined))
|
||||
|
||||
public static hintProperty = new dependencyObservable.Property("hint", "SearchBar", new proxy.PropertyMetadata(""))
|
||||
|
||||
public static textProperty = new dependencyObservable.Property(
|
||||
@@ -38,4 +41,13 @@ export class SearchBar extends view.View implements definition.SearchBar {
|
||||
this._setValue(SearchBar.textFieldBackgroundColorProperty,
|
||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||
}
|
||||
|
||||
get textFieldHintColor(): color.Color {
|
||||
return this._getValue(SearchBar.textFieldHintColorProperty);
|
||||
}
|
||||
set textFieldHintColor(value: color.Color) {
|
||||
this._setValue(SearchBar.textFieldHintColorProperty,
|
||||
value instanceof color.Color ? value : new color.Color(<any>value));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,6 +34,20 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr
|
||||
// register the setNativeValue callbacks
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
|
||||
|
||||
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bar = <SearchBar>data.object;
|
||||
if (!bar.android) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.newValue instanceof color.Color) {
|
||||
_changeSearchViewHintColor(bar.android, (<color.Color>data.newValue).android);
|
||||
}
|
||||
}
|
||||
|
||||
// register the setNativeValue callbacks
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldHintColorProperty.metadata).onSetNativeValue = onTextFieldHintColorPropertyChanged;
|
||||
|
||||
function onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bar = <SearchBar>data.object;
|
||||
if (!bar.android) {
|
||||
@@ -68,6 +82,14 @@ function _changeSearchViewBackgroundColor(bar: android.widget.SearchView, color:
|
||||
}
|
||||
}
|
||||
|
||||
function _changeSearchViewHintColor(bar: android.widget.SearchView, color: number) {
|
||||
var textView = getTextView(bar);
|
||||
|
||||
if (textView) {
|
||||
textView.setHintTextColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
require("utils/module-merge").merge(common, exports);
|
||||
@@ -128,6 +150,9 @@ export class SearchBar extends common.SearchBar {
|
||||
if (this.textFieldBackgroundColor instanceof color.Color) {
|
||||
_changeSearchViewBackgroundColor(this._android, this.textFieldBackgroundColor.android);
|
||||
}
|
||||
if (this.textFieldHintColor instanceof color.Color) {
|
||||
_changeSearchViewHintColor(this._android, this.textFieldHintColor.android);
|
||||
}
|
||||
}
|
||||
|
||||
get android(): android.widget.SearchView {
|
||||
|
||||
5
ui/search-bar/search-bar.d.ts
vendored
5
ui/search-bar/search-bar.d.ts
vendored
@@ -56,6 +56,11 @@ declare module "ui/search-bar" {
|
||||
*/
|
||||
textFieldBackgroundColor: color.Color;
|
||||
|
||||
/**
|
||||
* Gets or sets the TextField Hint color of the SearchBar component.
|
||||
*/
|
||||
textFieldHintColor: color.Color;
|
||||
|
||||
/**
|
||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
||||
|
||||
@@ -23,6 +23,20 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr
|
||||
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
|
||||
|
||||
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
|
||||
try {
|
||||
// TODO; convert this code into NativeScript Code
|
||||
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
|
||||
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
|
||||
} */
|
||||
} catch (Err) {
|
||||
// Do Nothing
|
||||
}
|
||||
}
|
||||
|
||||
(<proxy.PropertyMetadata>common.SearchBar.textFieldHintColorProperty.metadata).onSetNativeValue = onTextFieldHintColorPropertyChanged;
|
||||
|
||||
function onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var bar = <SearchBar>data.object;
|
||||
if (!bar.ios) {
|
||||
|
||||
Reference in New Issue
Block a user