mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Merge pull request #1013 from NativeScript/TextField-CSS-cursor-color
TextField CSS cursor color support added
This commit is contained in:
@ -6,6 +6,7 @@ import pagesModule = require("ui/page");
|
||||
import textFieldTestsNative = require("./text-field-tests-native");
|
||||
import colorModule = require("color");
|
||||
import enums = require("ui/enums");
|
||||
import platform = require("platform");
|
||||
|
||||
// <snippet module="ui/text-field" title="TextField">
|
||||
// # TextField
|
||||
@ -116,6 +117,17 @@ export var testBindTextDirectlyToModel = function () {
|
||||
});
|
||||
}
|
||||
|
||||
// Supported for ios only.
|
||||
if (platform.device.os === platform.platformNames.ios) {
|
||||
exports.test_set_color = function () {
|
||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||
var textField = <textFieldModule.TextField>views[0];
|
||||
textField.color = new colorModule.Color("red");
|
||||
TKUnit.assertEqual(textField.color.ios.CGColor, textField.ios.tintColor.CGColor, "textField.color");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export var testBindTextToBindingContext = function () {
|
||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||
var textField = <textFieldModule.TextField>views[0];
|
||||
|
@ -6,6 +6,7 @@ import pagesModule = require("ui/page");
|
||||
import textViewTestsNative = require("./text-view-tests-native");
|
||||
import colorModule = require("color");
|
||||
import enums = require("ui/enums");
|
||||
import platform = require("platform");
|
||||
|
||||
// <snippet module="ui/text-view" title="TextView">
|
||||
// # TextView
|
||||
@ -69,6 +70,17 @@ export var testSetText = function () {
|
||||
});
|
||||
}
|
||||
|
||||
// Supported for ios only.
|
||||
if (platform.device.os === platform.platformNames.ios) {
|
||||
exports.test_set_color = function () {
|
||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||
var textView = <textViewModule.TextView>views[0];
|
||||
textView.color = new colorModule.Color("red");
|
||||
TKUnit.assertEqual(textView.color.ios.CGColor, textView.ios.tintColor.CGColor, "textView.color");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export var testBindTextDirectlyToModel = function () {
|
||||
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||
var textView = <textViewModule.TextView>views[0];
|
||||
|
@ -358,6 +358,7 @@ export class TextViewStyler implements definition.stylers.Styler {
|
||||
}
|
||||
else {
|
||||
textView.textColor = color;
|
||||
textView.tintColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,6 +380,41 @@ export class TextViewStyler implements definition.stylers.Styler {
|
||||
}
|
||||
}
|
||||
|
||||
export class TextFieldStyler implements definition.stylers.Styler {
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
var tf: UITextField = <UITextField>view._nativeView;
|
||||
TextFieldStyler._setTextFieldColor(tf, newValue);
|
||||
}
|
||||
|
||||
private static resetColorProperty(view: view.View, nativeValue: any) {
|
||||
var tf: UITextField = <UITextField>view._nativeView;
|
||||
TextFieldStyler._setTextFieldColor(tf, nativeValue);
|
||||
}
|
||||
|
||||
private static _setTextFieldColor(tf: UITextField, newValue: any) {
|
||||
var color: UIColor = <UIColor>newValue;
|
||||
if ((<any>tf).isShowingHint && color) {
|
||||
tf.textColor = (<UIColor>color).colorWithAlphaComponent(0.22);
|
||||
}
|
||||
else {
|
||||
tf.textColor = color;
|
||||
tf.tintColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
private static getNativeColorValue(view: view.View): any {
|
||||
var tf: UITextField = <UITextField>view._nativeView;
|
||||
return tf.tintColor;
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.colorProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||
TextFieldStyler.setColorProperty,
|
||||
TextFieldStyler.resetColorProperty,
|
||||
TextFieldStyler.getNativeColorValue), "TextField");
|
||||
}
|
||||
}
|
||||
|
||||
export class SegmentedBarStyler implements definition.stylers.Styler {
|
||||
//Text color methods
|
||||
private static setColorProperty(view: view.View, newValue: any) {
|
||||
@ -585,6 +621,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.textColor = newValue;
|
||||
sf.tintColor = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,6 +629,7 @@ export class SearchBarStyler implements definition.stylers.Styler {
|
||||
var sf = <UITextField>(<any>view)._textField;
|
||||
if (sf) {
|
||||
sf.textColor = nativeValue;
|
||||
sf.tintColor = nativeValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -735,4 +773,5 @@ export function _registerDefaultStylers() {
|
||||
TabViewStyler.registerHandlers();
|
||||
ProgressStyler.registerHandlers();
|
||||
SwitchStyler.registerHandlers();
|
||||
TextFieldStyler.registerHandlers();
|
||||
}
|
||||
|
Reference in New Issue
Block a user