mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Merge pull request #1588 from NativeScript/null-undefined
TextView and TextField shows null and undefined
This commit is contained in:
@ -69,6 +69,31 @@ export var testSetText = function () {
|
|||||||
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export var testSetTextNull = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textField = <textFieldModule.TextField>views[0];
|
||||||
|
|
||||||
|
textField.text = null;
|
||||||
|
|
||||||
|
var expectedValue = "";
|
||||||
|
var actualValue = textFieldTestsNative.getNativeText(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export var testSetTextUndefined = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textField = <textFieldModule.TextField>views[0];
|
||||||
|
|
||||||
|
textField.text = undefined;
|
||||||
|
|
||||||
|
var expectedValue = "";
|
||||||
|
var actualValue = textFieldTestsNative.getNativeText(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
export var testSetHintToNumber = function () {
|
export var testSetHintToNumber = function () {
|
||||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
@ -70,6 +70,30 @@ export var testSetText = function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export var testSetTextNull = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textView = <textViewModule.TextView>views[0];
|
||||||
|
|
||||||
|
textView.text = null;
|
||||||
|
|
||||||
|
var expectedValue = "";
|
||||||
|
var actualValue = textViewTestsNative.getNativeText(textView);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export var testSetTextUndefined = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textView = <textViewModule.TextView>views[0];
|
||||||
|
|
||||||
|
textView.text = undefined;
|
||||||
|
|
||||||
|
var expectedValue = "";
|
||||||
|
var actualValue = textViewTestsNative.getNativeText(textView);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Supported for ios only.
|
// Supported for ios only.
|
||||||
if (platform.device.os === platform.platformNames.ios) {
|
if (platform.device.os === platform.platformNames.ios) {
|
||||||
exports.test_set_color = function () {
|
exports.test_set_color = function () {
|
||||||
|
@ -3,6 +3,7 @@ import textBase = require("ui/text-base");
|
|||||||
import dependencyObservable = require("ui/core/dependency-observable");
|
import dependencyObservable = require("ui/core/dependency-observable");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
export class EditableTextBase extends common.EditableTextBase {
|
export class EditableTextBase extends common.EditableTextBase {
|
||||||
private _android: android.widget.EditText;
|
private _android: android.widget.EditText;
|
||||||
@ -131,7 +132,8 @@ export class EditableTextBase extends common.EditableTextBase {
|
|||||||
|
|
||||||
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||||
if (this._android) {
|
if (this._android) {
|
||||||
this.android.setText(data.newValue + "", android.widget.TextView.BufferType.EDITABLE);
|
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
|
||||||
|
this.android.setText(newValue, android.widget.TextView.BufferType.EDITABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import enums = require("ui/enums");
|
|||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import style = require("ui/styling/style");
|
import style = require("ui/styling/style");
|
||||||
import styling = require("ui/styling");
|
import styling = require("ui/styling");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
global.moduleMerge(common, exports);
|
global.moduleMerge(common, exports);
|
||||||
|
|
||||||
@ -118,13 +119,13 @@ export class TextView extends common.TextView {
|
|||||||
|
|
||||||
public _showHint(hint: string) {
|
public _showHint(hint: string) {
|
||||||
this.ios.textColor = this.ios.textColor ? this.ios.textColor.colorWithAlphaComponent(0.22) : UIColor.blackColor().colorWithAlphaComponent(0.22);
|
this.ios.textColor = this.ios.textColor ? this.ios.textColor.colorWithAlphaComponent(0.22) : UIColor.blackColor().colorWithAlphaComponent(0.22);
|
||||||
this.ios.text = hint + "";
|
this.ios.text = types.isNullOrUndefined(hint) ? "" : hint + "";
|
||||||
(<any>this.ios).isShowingHint = true;
|
(<any>this.ios).isShowingHint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _hideHint() {
|
public _hideHint() {
|
||||||
this.ios.textColor = this.color ? this.color.ios : null;
|
this.ios.textColor = this.color ? this.color.ios : null;
|
||||||
this.ios.text = this.text + "";
|
this.ios.text = types.isNullOrUndefined(this.text) ? "" : this.text + "";
|
||||||
(<any>this.ios).isShowingHint = false;
|
(<any>this.ios).isShowingHint = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user