This commit is contained in:
Rossen Hristov
2015-05-20 16:45:02 +03:00
parent be188119f0
commit f6a92d85a4
3 changed files with 64 additions and 11 deletions

View File

@@ -8,8 +8,8 @@ export function getNativeText(textView: textViewModule.TextView): string {
}
export function getNativeHint(textView: textViewModule.TextView): string {
// There is no native hint
if (textView.hint !== "") {
// There is no native hint so we use a hack and sett 22% opaque text.
if ((<any>textView.ios).isShowingHint) {
return textView.ios.text;
}

View File

@@ -138,6 +138,7 @@ export var testTextIsUpdatedWhenUserTypes = function () {
export var testSetHint = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
textView.text = "";
// <snippet module="ui/text-view" title="TextView">
// ### Setting the hint of a TextView
@@ -155,6 +156,7 @@ export var testSetHint = function () {
export var testBindHintDirectlyToModel = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
textView.text = "";
// <snippet module="ui/text-view" title="TextView">
// ### Binding hint property directly to model
@@ -168,13 +170,13 @@ export var testBindHintDirectlyToModel = function () {
textView.bind(options, model);
//// TextView.hint is now "type your username here"
// <hide>
TKUnit.assert(textView.hint === "type your username here", "Actual: " + textView.text + "; Expected: " + "type your username here");
TKUnit.assert(textView.hint === "type your username here", "Actual: " + textView.hint + "; Expected: " + "type your username here");
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your username here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your username here");
// </hide>
model.set("hint", "type your password here");
//// TextView.hint is now "type your password here"
// <hide>
TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.text + "; Expected: " + "type your password here");
TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.hint + "; Expected: " + "type your password here");
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your password here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your password here");
// </hide>
// ```
@@ -185,6 +187,7 @@ export var testBindHintDirectlyToModel = function () {
export var testBindHintToBindingConext = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
textView.text = "";
var page = <pagesModule.Page>views[1];
var model = new observable.Observable();
@@ -201,11 +204,61 @@ export var testBindHintToBindingConext = function () {
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your username here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your username here");
model.set("hint", "type your password here");
TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.text + "; Expected: " + "type your password here");
TKUnit.assert(textView.hint === "type your password here", "Actual: " + textView.hint + "; Expected: " + "type your password here");
TKUnit.assert(textViewTestsNative.getNativeHint(textView) === "type your password here", "Actual: " + textViewTestsNative.getNativeHint(textView) + "; Expected: " + "type your password here");
});
}
export var testHintPlusTextiOS = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
if (!textView.ios) {
return;
}
var expectedValue;
var actualValue;
textView.hint = "hint";
textView.text = "text";
expectedValue = "text";
actualValue = textViewTestsNative.getNativeText(textView);
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
textView.text = "";
expectedValue = "hint";
actualValue = textViewTestsNative.getNativeText(textView);
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
});
}
export var testHintColoriOS = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
if (!textView.ios) {
return;
}
textView.text = "";
textView.color = new colorModule.Color("red");
textView.hint = "hint";
var expectedValue;
var actualValue;
expectedValue = "#38.1999948ff0000"; // 22% red
actualValue = textViewTestsNative.getNativeColor(textView).hex;
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
textView.text = "text";
expectedValue = "#ffff0000"; // red
actualValue = textViewTestsNative.getNativeColor(textView).hex;
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
});
}
export var testSetEditable = function () {
helper.buildUIAndRunTest(_createTextViewFunc(), function (views: Array<viewModule.View>) {
var textView = <textViewModule.TextView>views[0];
@@ -413,4 +466,4 @@ export var testMemoryLeak = function () {
helper.buildUIWithWeakRefAndInteract(_createTextViewFunc, function (textView) {
textViewTestsNative.typeTextNatively(textView, "Hello, world!");
});
}
}

View File

@@ -32,7 +32,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
}
this._owner.dismissSoftInput();
this._owner._refreshHintState(this._owner.hint);
this._owner._refreshHintState(this._owner.hint, textView.text);
}
public textViewDidChange(textView: UITextView) {
@@ -77,16 +77,16 @@ export class TextView extends common.TextView {
}
public _onHintPropertyChanged(data: dependencyObservable.PropertyChangeData) {
this._refreshHintState(data.newValue);
this._refreshHintState(data.newValue, this.text);
}
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
super._onTextPropertyChanged(data);
this._refreshHintState(this.hint);
this._refreshHintState(this.hint, data.newValue);
}
public _refreshHintState(hint: string) {
if (hint && !this.ios.text) {
public _refreshHintState(hint: string, text: string) {
if (hint && !text) {
this._showHint(hint);
}
else {