From 173620be7953d6613b88759a7b69f82e8187aa5a Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Tue, 14 Jun 2016 17:17:21 +0300 Subject: [PATCH] Fixed: SearchBar.textFieldHintColor not respected on iOS Resolves #1807 --- .../ui/search-bar/search-bar.ios.ts | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/tns-core-modules/ui/search-bar/search-bar.ios.ts b/tns-core-modules/ui/search-bar/search-bar.ios.ts index 2fd3d40ce..146bd5eb8 100644 --- a/tns-core-modules/ui/search-bar/search-bar.ios.ts +++ b/tns-core-modules/ui/search-bar/search-bar.ios.ts @@ -5,6 +5,7 @@ import * as typesModule from "utils/types"; import style = require("ui/styling/style"); import view = require("ui/core/view"); import font = require("ui/styling/font"); +import { Color } from "color"; var types: typeof typesModule; function ensureTypes() { @@ -21,12 +22,10 @@ function onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) { (common.SearchBar.textProperty.metadata).onSetNativeValue = onTextPropertyChanged; function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) { - var bar = data.object; - var color = require("color"); - if (data.newValue instanceof color.Color) { - var tf = (bar)._textField; - if (tf) { - tf.backgroundColor = data.newValue.ios; + if (data.newValue instanceof Color) { + let bar = data.object; + if (bar._textField) { + bar._textField.backgroundColor = data.newValue.ios; } } } @@ -34,14 +33,11 @@ function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.Pr (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 + if (data.newValue instanceof Color) { + let bar = data.object; + if (bar._placeholderLabel) { + bar._placeholderLabel.textColor = data.newValue.ios; + } } } @@ -115,6 +111,7 @@ export class SearchBar extends common.SearchBar { private _ios: UISearchBar; private _delegate; private __textField: UITextField; + private __placeholderLabel: UILabel; constructor() { super(); @@ -149,6 +146,16 @@ export class SearchBar extends common.SearchBar { 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 {