Fixed: SearchBar.textFieldHintColor not respected on iOS

Resolves #1807
This commit is contained in:
Rossen Hristov
2016-06-14 17:17:21 +03:00
parent 3962ac11a2
commit 173620be79

View File

@ -5,6 +5,7 @@ import * as typesModule from "utils/types";
import style = require("ui/styling/style"); import style = require("ui/styling/style");
import view = require("ui/core/view"); import view = require("ui/core/view");
import font = require("ui/styling/font"); import font = require("ui/styling/font");
import { Color } from "color";
var types: typeof typesModule; var types: typeof typesModule;
function ensureTypes() { function ensureTypes() {
@ -21,12 +22,10 @@ function onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
(<proxy.PropertyMetadata>common.SearchBar.textProperty.metadata).onSetNativeValue = onTextPropertyChanged; (<proxy.PropertyMetadata>common.SearchBar.textProperty.metadata).onSetNativeValue = onTextPropertyChanged;
function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) { function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var bar = <SearchBar>data.object; if (data.newValue instanceof Color) {
var color = require("color"); let bar = <SearchBar>data.object;
if (data.newValue instanceof color.Color) { if (bar._textField) {
var tf = (<any>bar)._textField; bar._textField.backgroundColor = data.newValue.ios;
if (tf) {
tf.backgroundColor = data.newValue.ios;
} }
} }
} }
@ -34,14 +33,11 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged; (<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) { function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
// This should be in a Try Catch in case Apple eliminates which ever method in the future; if (data.newValue instanceof Color) {
try { let bar = <SearchBar>data.object;
// TODO; convert this code into NativeScript Code if (bar._placeholderLabel) {
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) { bar._placeholderLabel.textColor = data.newValue.ios;
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; }
} */
} catch (Err) {
// Do Nothing
} }
} }
@ -115,6 +111,7 @@ export class SearchBar extends common.SearchBar {
private _ios: UISearchBar; private _ios: UISearchBar;
private _delegate; private _delegate;
private __textField: UITextField; private __textField: UITextField;
private __placeholderLabel: UILabel;
constructor() { constructor() {
super(); super();
@ -149,6 +146,16 @@ export class SearchBar extends common.SearchBar {
return this.__textField; return this.__textField;
} }
get _placeholderLabel(): UILabel {
if (!this.__placeholderLabel) {
if (this._textField){
this.__placeholderLabel = this._textField.valueForKey("placeholderLabel");
}
}
return this.__placeholderLabel;
}
} }
export class SearchBarStyler implements style.Styler { export class SearchBarStyler implements style.Styler {