Merge pull request #1533 from NativeScript/label-null

Fixed null and undefined as Label text
This commit is contained in:
Vladimir Enchev
2016-02-11 11:44:18 +02:00
2 changed files with 38 additions and 2 deletions

View File

@ -89,6 +89,40 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
}
public test_Set_Text_Native_Null() {
var testLabel = this.testView;
var expectedValue = "";
testLabel.text = null;
var actualNative;
if (testLabel.ios) {
actualNative = testLabel.ios.text;
}
else {
this.waitUntilTestElementIsLoaded();
actualNative = testLabel.android.getText();
}
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
}
public test_Set_Text_Native_Undefined() {
var testLabel = this.testView;
var expectedValue = "";
testLabel.text = undefined;
var actualNative;
if (testLabel.ios) {
actualNative = testLabel.ios.text;
}
else {
this.waitUntilTestElementIsLoaded();
actualNative = testLabel.android.getText();
}
TKUnit.assertEqual(actualNative, expectedValue, "Native text not equal");
}
public test_Set_BackgroundColor_TNS() {
var label = this.testView;
var expectedValue = new colorModule.Color("Red");

View File

@ -1,5 +1,6 @@
import definition = require("ui/text-base");
import view = require("ui/core/view");
import types = require("utils/types");
import observable = require("data/observable");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
@ -100,11 +101,12 @@ export class TextBase extends view.View implements definition.TextBase, formatte
}
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var newValue = types.isNullOrUndefined(data.newValue) ? "" : data.newValue + "";
if (this.android) {
this.android.setText(data.newValue + "");
this.android.setText(newValue);
}
else if (this.ios) {
this.ios.text = data.newValue + "";
this.ios.text = newValue;
this.style._updateTextDecoration();
this.style._updateTextTransform();
}