Skip to content

Commit 69199a5

Browse files
Fix hint color in ios, the attributedPlaceholder and placeholder was set following two very distinct paths (NativeScript#4945)
1 parent 374f31c commit 69199a5

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

tns-core-modules/ui/text-field/text-field.ios.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ export class TextField extends TextFieldBase {
172172
return this.nativeViewProtected.placeholder;
173173
}
174174
[hintProperty.setNative](value: string) {
175-
let stringValue;
176-
if (value === null || value === void 0) {
177-
stringValue = "";
178-
} else {
179-
stringValue = value + "";
180-
}
181-
this.nativeViewProtected.placeholder = stringValue;
175+
this._updateAttributedPlaceholder();
182176
}
183177

184178
[secureProperty.getDefault](): boolean {
@@ -209,18 +203,29 @@ export class TextField extends TextFieldBase {
209203
return null;
210204
}
211205
[placeholderColorProperty.setNative](value: UIColor | Color) {
212-
let nativeView = this.nativeViewProtected;
213-
let colorAttibutes = NSMutableDictionary.new<string, any>();
214-
colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName);
215-
let stringValue;
216-
if (nativeView.placeholder === null || nativeView.placeholder === void 0) {
206+
this._updateAttributedPlaceholder();
207+
}
208+
209+
_updateAttributedPlaceholder(): void {
210+
let stringValue = this.hint;
211+
if (stringValue === null || stringValue === void 0) {
212+
stringValue = "";
213+
} else {
214+
stringValue = stringValue + "";
215+
}
216+
if (stringValue === "") {
217217
// we do not use empty string since initWithStringAttributes does not return proper value and
218218
// nativeView.attributedPlaceholder will be null
219219
stringValue = " ";
220+
}
221+
if (placeholderColorProperty.isSet(this.style)) {
222+
const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, <any>{
223+
[NSForegroundColorAttributeName]: this.style.placeholderColor.ios
224+
});
225+
this.nativeViewProtected.attributedPlaceholder = attributedPlaceholder;
220226
} else {
221-
stringValue = nativeView.placeholder + "";
227+
this.nativeViewProtected.placeholder = stringValue;
222228
}
223-
nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, colorAttibutes);
224229
}
225230

226231
[paddingTopProperty.getDefault](): Length {

0 commit comments

Comments
 (0)