Skip to content

Commit 173620b

Browse files
committed
Fixed: SearchBar.textFieldHintColor not respected on iOS
Resolves NativeScript#1807
1 parent 3962ac1 commit 173620b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

tns-core-modules/ui/search-bar/search-bar.ios.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as typesModule from "utils/types";
55
import style = require("ui/styling/style");
66
import view = require("ui/core/view");
77
import font = require("ui/styling/font");
8+
import { Color } from "color";
89

910
var types: typeof typesModule;
1011
function ensureTypes() {
@@ -21,27 +22,22 @@ function onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
2122
(<proxy.PropertyMetadata>common.SearchBar.textProperty.metadata).onSetNativeValue = onTextPropertyChanged;
2223

2324
function onTextFieldBackgroundColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
24-
var bar = <SearchBar>data.object;
25-
var color = require("color");
26-
if (data.newValue instanceof color.Color) {
27-
var tf = (<any>bar)._textField;
28-
if (tf) {
29-
tf.backgroundColor = data.newValue.ios;
25+
if (data.newValue instanceof Color) {
26+
let bar = <SearchBar>data.object;
27+
if (bar._textField) {
28+
bar._textField.backgroundColor = data.newValue.ios;
3029
}
3130
}
3231
}
3332

3433
(<proxy.PropertyMetadata>common.SearchBar.textFieldBackgroundColorProperty.metadata).onSetNativeValue = onTextFieldBackgroundColorPropertyChanged;
3534

3635
function onTextFieldHintColorPropertyChanged(data: dependencyObservable.PropertyChangeData) {
37-
// This should be in a Try Catch in case Apple eliminates which ever method in the future;
38-
try {
39-
// TODO; convert this code into NativeScript Code
40-
/* if ([textField respondsToSelector:@selector(setAttributedPlaceholder:)]) {
41-
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:textField.placeholder attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
42-
} */
43-
} catch (Err) {
44-
// Do Nothing
36+
if (data.newValue instanceof Color) {
37+
let bar = <SearchBar>data.object;
38+
if (bar._placeholderLabel) {
39+
bar._placeholderLabel.textColor = data.newValue.ios;
40+
}
4541
}
4642
}
4743

@@ -115,6 +111,7 @@ export class SearchBar extends common.SearchBar {
115111
private _ios: UISearchBar;
116112
private _delegate;
117113
private __textField: UITextField;
114+
private __placeholderLabel: UILabel;
118115

119116
constructor() {
120117
super();
@@ -149,6 +146,16 @@ export class SearchBar extends common.SearchBar {
149146

150147
return this.__textField;
151148
}
149+
150+
get _placeholderLabel(): UILabel {
151+
if (!this.__placeholderLabel) {
152+
if (this._textField){
153+
this.__placeholderLabel = this._textField.valueForKey("placeholderLabel");
154+
}
155+
}
156+
157+
return this.__placeholderLabel;
158+
}
152159
}
153160

154161
export class SearchBarStyler implements style.Styler {

0 commit comments

Comments
 (0)