Merge pull request #4292 from NativeScript/fix-ios-text-view-hint

Fix: IOS text view hint should never show while editing
This commit is contained in:
Alexander Vakrilov
2017-06-01 13:31:28 +03:00
committed by GitHub
4 changed files with 23 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
export function clear(args) {
const tv = args.object.page.getViewById("tv");
tv.text= "";
}

View File

@@ -0,0 +1,6 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<StackLayout class="p-20">
<TextView id="tv" text="" hint="the hint" ></TextView>
<Button text="clear text" tap="clear"></Button>
</StackLayout>
</Page>

View File

@@ -23,6 +23,7 @@ export function pageLoaded(args: EventData) {
examples.set("1639", "issues/issue-1639");
examples.set("1657-ios", "issues/issue-1657-ios");
examples.set("tabview-with-scrollview_4022","issues/tabview-with-scrollview_4022");
examples.set("3354-ios", "issues/issue-3354");
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
page.bindingContext = viewModel;

View File

@@ -2,7 +2,7 @@
import {
EditableTextBase, editableProperty, hintProperty, textProperty, colorProperty, placeholderColorProperty,
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
Length, _updateCharactersInRangeReplacementString, Color, layout
} from "../editable-text-base";
@@ -28,6 +28,13 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
return true;
}
public textViewDidBeginEditing(textView: UITextView) {
var owner = this._owner.get();
if (owner) {
owner._isEditing = true;
}
}
public textViewDidEndEditing(textView: UITextView) {
const owner = this._owner.get();
if (owner) {
@@ -35,6 +42,7 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
textProperty.nativeValueChange(owner, textView.text);
}
owner._isEditing = false;
owner.dismissSoftInput();
owner._refreshHintState(owner.hint, textView.text);
}
@@ -63,6 +71,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
private _ios: UITextView;
private _delegate: UITextViewDelegateImpl;
private _isShowingHint: boolean;
public _isEditing: boolean;
constructor() {
super();
@@ -96,9 +105,10 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
if (this.formattedText) {
return;
}
if (text !== null && text !== undefined && text !== '') {
this.showText();
} else if (hint !== null && hint !== undefined && hint !== '') {
} else if (!this._isEditing && hint !== null && hint !== undefined && hint !== '') {
this.showHint(hint);
} else {
this._isShowingHint = false;