mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix hint color in ios, the attributedPlaceholder and placeholder was set following two very distinct paths (#4945)
This commit is contained in:
@@ -172,13 +172,7 @@ export class TextField extends TextFieldBase {
|
||||
return this.nativeViewProtected.placeholder;
|
||||
}
|
||||
[hintProperty.setNative](value: string) {
|
||||
let stringValue;
|
||||
if (value === null || value === void 0) {
|
||||
stringValue = "";
|
||||
} else {
|
||||
stringValue = value + "";
|
||||
}
|
||||
this.nativeViewProtected.placeholder = stringValue;
|
||||
this._updateAttributedPlaceholder();
|
||||
}
|
||||
|
||||
[secureProperty.getDefault](): boolean {
|
||||
@@ -209,18 +203,29 @@ export class TextField extends TextFieldBase {
|
||||
return null;
|
||||
}
|
||||
[placeholderColorProperty.setNative](value: UIColor | Color) {
|
||||
let nativeView = this.nativeViewProtected;
|
||||
let colorAttibutes = NSMutableDictionary.new<string, any>();
|
||||
colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName);
|
||||
let stringValue;
|
||||
if (nativeView.placeholder === null || nativeView.placeholder === void 0) {
|
||||
this._updateAttributedPlaceholder();
|
||||
}
|
||||
|
||||
_updateAttributedPlaceholder(): void {
|
||||
let stringValue = this.hint;
|
||||
if (stringValue === null || stringValue === void 0) {
|
||||
stringValue = "";
|
||||
} else {
|
||||
stringValue = stringValue + "";
|
||||
}
|
||||
if (stringValue === "") {
|
||||
// we do not use empty string since initWithStringAttributes does not return proper value and
|
||||
// nativeView.attributedPlaceholder will be null
|
||||
stringValue = " ";
|
||||
} else {
|
||||
stringValue = nativeView.placeholder + "";
|
||||
}
|
||||
nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, colorAttibutes);
|
||||
if (placeholderColorProperty.isSet(this.style)) {
|
||||
const attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(stringValue, <any>{
|
||||
[NSForegroundColorAttributeName]: this.style.placeholderColor.ios
|
||||
});
|
||||
this.nativeViewProtected.attributedPlaceholder = attributedPlaceholder;
|
||||
} else {
|
||||
this.nativeViewProtected.placeholder = stringValue;
|
||||
}
|
||||
}
|
||||
|
||||
[paddingTopProperty.getDefault](): Length {
|
||||
|
||||
Reference in New Issue
Block a user