@@ -71,7 +71,6 @@ export class SearchBar extends SearchBarBase {
7171 nativeViewProtected : UISearchBar ;
7272 private _delegate ;
7373 private __textField : UITextField ;
74- private __placeholderLabel : UILabel ;
7574
7675 createNativeView ( ) {
7776 return UISearchBarImpl . new ( ) ;
@@ -113,16 +112,6 @@ export class SearchBar extends SearchBarBase {
113112 return this . __textField ;
114113 }
115114
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-
126115 [ isEnabledProperty . setNative ] ( value : boolean ) {
127116 const nativeView = this . nativeViewProtected ;
128117 if ( nativeView instanceof UIControl ) {
@@ -189,8 +178,7 @@ export class SearchBar extends SearchBarBase {
189178 return "" ;
190179 }
191180 [ hintProperty . setNative ] ( value : string ) {
192- const text = ( value === null || value === undefined ) ? "" : value . toString ( ) ;
193- this . ios . placeholder = text ;
181+ this . _updateAttributedPlaceholder ( ) ;
194182 }
195183
196184 [ textFieldBackgroundColorProperty . getDefault ] ( ) : UIColor {
@@ -210,18 +198,30 @@ export class SearchBar extends SearchBarBase {
210198 }
211199
212200 [ textFieldHintColorProperty . getDefault ] ( ) : UIColor {
213- const placeholderLabel = this . _placeholderLabel ;
214- if ( placeholderLabel ) {
215- return placeholderLabel . textColor ;
216- }
217-
218201 return null ;
219202 }
220203 [ 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 ;
225223 }
224+ const attributedPlaceholder = NSAttributedString . alloc ( ) . initWithStringAttributes ( stringValue , attributes ) ;
225+ this . _textField . attributedPlaceholder = attributedPlaceholder ;
226226 }
227227}
0 commit comments