Fix hint color in ios, the attributedPlaceholder and placeholder was set following two very distinct paths (#4945)

This commit is contained in:
Panayot Cankov
2017-10-18 16:10:23 +03:00
committed by GitHub
parent 374f31cbf7
commit 69199a5df2

View File

@@ -172,13 +172,7 @@ export class TextField extends TextFieldBase {
return this.nativeViewProtected.placeholder; return this.nativeViewProtected.placeholder;
} }
[hintProperty.setNative](value: string) { [hintProperty.setNative](value: string) {
let stringValue; this._updateAttributedPlaceholder();
if (value === null || value === void 0) {
stringValue = "";
} else {
stringValue = value + "";
}
this.nativeViewProtected.placeholder = stringValue;
} }
[secureProperty.getDefault](): boolean { [secureProperty.getDefault](): boolean {
@@ -209,18 +203,29 @@ export class TextField extends TextFieldBase {
return null; return null;
} }
[placeholderColorProperty.setNative](value: UIColor | Color) { [placeholderColorProperty.setNative](value: UIColor | Color) {
let nativeView = this.nativeViewProtected; this._updateAttributedPlaceholder();
let colorAttibutes = NSMutableDictionary.new<string, any>(); }
colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName);
let stringValue; _updateAttributedPlaceholder(): void {
if (nativeView.placeholder === null || nativeView.placeholder === void 0) { 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 // we do not use empty string since initWithStringAttributes does not return proper value and
// nativeView.attributedPlaceholder will be null // nativeView.attributedPlaceholder will be null
stringValue = " "; 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 { [paddingTopProperty.getDefault](): Length {