mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Fixed(IOS): Setting placeholder color on text filed crashes if no hint is set
This commit is contained in:
@ -576,3 +576,13 @@ export function test_set_placeholder_color() {
|
|||||||
TKUnit.assertEqual(actualColorHex, expectedColorHex);
|
TKUnit.assertEqual(actualColorHex, expectedColorHex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function test_set_placeholder_color_when_hint_is_not_set() {
|
||||||
|
let view = new textFieldModule.TextField();
|
||||||
|
let expectedColorHex = "#ffff0000";
|
||||||
|
helper.buildUIAndRunTest(view, function (views: Array<viewModule.View>) {
|
||||||
|
view.setInlineStyle("placeholder-color: " + expectedColorHex + ";");
|
||||||
|
let actualColorHex = textFieldTestsNative.getNativePlaceholderColor(view).hex;
|
||||||
|
TKUnit.assertEqual(actualColorHex, expectedColorHex);
|
||||||
|
});
|
||||||
|
}
|
@ -7,7 +7,7 @@ import * as style from "ui/styling/style";
|
|||||||
import {View} from "ui/core/view";
|
import {View} from "ui/core/view";
|
||||||
|
|
||||||
function onSecurePropertyChanged(data: PropertyChangeData) {
|
function onSecurePropertyChanged(data: PropertyChangeData) {
|
||||||
var textField = <TextField>data.object;
|
const textField = <TextField>data.object;
|
||||||
textField.ios.secureTextEntry = data.newValue;
|
textField.ios.secureTextEntry = data.newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,24 +156,24 @@ export class TextField extends common.TextField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _onHintPropertyChanged(data: PropertyChangeData) {
|
public _onHintPropertyChanged(data: PropertyChangeData) {
|
||||||
var textField = <TextField>data.object;
|
const textField = <TextField>data.object;
|
||||||
textField.ios.placeholder = data.newValue + "";
|
textField.ios.placeholder = data.newValue + "";
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export class TextFieldStyler implements style.Styler {
|
export class TextFieldStyler implements style.Styler {
|
||||||
private static setColorProperty(view: View, newValue: any) {
|
private static setColorProperty(view: View, newValue: any) {
|
||||||
var tf: UITextField = <UITextField>view._nativeView;
|
const tf: UITextField = <UITextField>view._nativeView;
|
||||||
TextFieldStyler._setTextFieldColor(tf, newValue);
|
TextFieldStyler._setTextFieldColor(tf, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resetColorProperty(view: View, nativeValue: any) {
|
private static resetColorProperty(view: View, nativeValue: any) {
|
||||||
var tf: UITextField = <UITextField>view._nativeView;
|
const tf: UITextField = <UITextField>view._nativeView;
|
||||||
TextFieldStyler._setTextFieldColor(tf, nativeValue);
|
TextFieldStyler._setTextFieldColor(tf, nativeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _setTextFieldColor(tf: UITextField, newValue: any) {
|
private static _setTextFieldColor(tf: UITextField, newValue: any) {
|
||||||
var color: UIColor = <UIColor>newValue;
|
const color: UIColor = <UIColor>newValue;
|
||||||
if ((<any>tf).isShowingHint && color) {
|
if ((<any>tf).isShowingHint && color) {
|
||||||
tf.textColor = (<UIColor>color).colorWithAlphaComponent(0.22);
|
tf.textColor = (<UIColor>color).colorWithAlphaComponent(0.22);
|
||||||
}
|
}
|
||||||
@ -184,27 +184,32 @@ export class TextFieldStyler implements style.Styler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static getNativeColorValue(view: View): any {
|
private static getNativeColorValue(view: View): any {
|
||||||
var tf: UITextField = <UITextField>view._nativeView;
|
const tf: UITextField = <UITextField>view._nativeView;
|
||||||
return tf.tintColor;
|
return tf.tintColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// placeholder-color
|
// placeholder-color
|
||||||
private static setPlaceholderColorProperty(textBase: View, newValue: any) {
|
private static setPlaceholderColorProperty(textBase: View, newValue: any) {
|
||||||
let ios = <UITextField>textBase._nativeView;
|
const ios = <UITextField>textBase._nativeView;
|
||||||
let colorAttibutes = NSMutableDictionary.alloc().init();
|
const text = ios.placeholder + "";
|
||||||
colorAttibutes.setValueForKey(newValue, NSForegroundColorAttributeName);
|
const colorAttributes = NSMutableDictionary.alloc().init();
|
||||||
ios.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(ios.placeholder, colorAttibutes.copy());
|
colorAttributes.setValueForKey(newValue, NSForegroundColorAttributeName);
|
||||||
|
ios.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(text, colorAttributes.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static resetPlaceholderColorProperty(textBase: View, nativeValue: any) {
|
private static resetPlaceholderColorProperty(textBase: View, nativeValue: any) {
|
||||||
var ios = <UITextField>textBase._nativeView;
|
const ios = <UITextField>textBase._nativeView;
|
||||||
let colorAttibutes = NSMutableDictionary.alloc().init();
|
const text = ios.placeholder + "";
|
||||||
colorAttibutes.setValueForKey(nativeValue, NSForegroundColorAttributeName);
|
const colorAttributes = NSMutableDictionary.alloc().init();
|
||||||
ios.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(ios.placeholder, colorAttibutes.copy());
|
colorAttributes.setValueForKey(nativeValue, NSForegroundColorAttributeName);
|
||||||
|
ios.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(text, colorAttributes.copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getNativePlaceholderColorValue(textBase: View): any {
|
private static getNativePlaceholderColorValue(textBase: View): any {
|
||||||
var ios = <UITextField>textBase._nativeView;
|
const ios = <UITextField>textBase._nativeView;
|
||||||
|
if (!ios.attributedPlaceholder) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return ios.attributedPlaceholder.attributeAtIndexEffectiveRange(NSForegroundColorAttributeName, 0, null);
|
return ios.attributedPlaceholder.attributeAtIndexEffectiveRange(NSForegroundColorAttributeName, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user