@@ -71,7 +71,6 @@ export class SearchBar extends SearchBarBase {
71
71
nativeViewProtected : UISearchBar ;
72
72
private _delegate ;
73
73
private __textField : UITextField ;
74
- private __placeholderLabel : UILabel ;
75
74
76
75
createNativeView ( ) {
77
76
return UISearchBarImpl . new ( ) ;
@@ -113,16 +112,6 @@ export class SearchBar extends SearchBarBase {
113
112
return this . __textField ;
114
113
}
115
114
116
- get _placeholderLabel ( ) : UILabel {
117
- if ( ! this . __placeholderLabel ) {
118
- if ( this . _textField ) {
119
- this . __placeholderLabel = this . _textField . valueForKey ( "placeholderLabel" ) ;
120
- }
121
- }
122
-
123
- return this . __placeholderLabel ;
124
- }
125
-
126
115
[ isEnabledProperty . setNative ] ( value : boolean ) {
127
116
const nativeView = this . nativeViewProtected ;
128
117
if ( nativeView instanceof UIControl ) {
@@ -189,8 +178,7 @@ export class SearchBar extends SearchBarBase {
189
178
return "" ;
190
179
}
191
180
[ hintProperty . setNative ] ( value : string ) {
192
- const text = ( value === null || value === undefined ) ? "" : value . toString ( ) ;
193
- this . ios . placeholder = text ;
181
+ this . _updateAttributedPlaceholder ( ) ;
194
182
}
195
183
196
184
[ textFieldBackgroundColorProperty . getDefault ] ( ) : UIColor {
@@ -210,18 +198,30 @@ export class SearchBar extends SearchBarBase {
210
198
}
211
199
212
200
[ textFieldHintColorProperty . getDefault ] ( ) : UIColor {
213
- const placeholderLabel = this . _placeholderLabel ;
214
- if ( placeholderLabel ) {
215
- return placeholderLabel . textColor ;
216
- }
217
-
218
201
return null ;
219
202
}
220
203
[ textFieldHintColorProperty . setNative ] ( value : Color | UIColor ) {
221
- const color = value instanceof Color ? value . ios : value
222
- const placeholderLabel = this . _placeholderLabel ;
223
- if ( placeholderLabel ) {
224
- placeholderLabel . textColor = color ;
204
+ this . _updateAttributedPlaceholder ( ) ;
205
+ }
206
+
207
+ // Very similar to text-field.ios.ts implementation. Maybe unify APIs and base classes?
208
+ _updateAttributedPlaceholder ( ) : void {
209
+ let stringValue = this . hint ;
210
+ if ( stringValue === null || stringValue === void 0 ) {
211
+ stringValue = "" ;
212
+ } else {
213
+ stringValue = stringValue + "" ;
214
+ }
215
+ if ( stringValue === "" ) {
216
+ // we do not use empty string since initWithStringAttributes does not return proper value and
217
+ // nativeView.attributedPlaceholder will be null
218
+ stringValue = " " ;
219
+ }
220
+ const attributes : any = { } ;
221
+ if ( this . textFieldHintColor ) {
222
+ attributes [ NSForegroundColorAttributeName ] = this . textFieldHintColor . ios ;
225
223
}
224
+ const attributedPlaceholder = NSAttributedString . alloc ( ) . initWithStringAttributes ( stringValue , attributes ) ;
225
+ this . _textField . attributedPlaceholder = attributedPlaceholder ;
226
226
}
227
227
}
0 commit comments