Skip to content

Commit 9f47746

Browse files
author
Alexander Vakrilov
authored
Merge pull request NativeScript#4292 from NativeScript/fix-ios-text-view-hint
Fix: IOS text view hint should never show while editing
2 parents 4862443 + 4509f04 commit 9f47746

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function clear(args) {
2+
const tv = args.object.page.getViewById("tv");
3+
tv.text= "";
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
2+
<StackLayout class="p-20">
3+
<TextView id="tv" text="" hint="the hint" ></TextView>
4+
<Button text="clear text" tap="clear"></Button>
5+
</StackLayout>
6+
</Page>

‎apps/app/ui-tests-app/issues/main-page.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function pageLoaded(args: EventData) {
2323
examples.set("1639", "issues/issue-1639");
2424
examples.set("1657-ios", "issues/issue-1657-ios");
2525
examples.set("tabview-with-scrollview_4022","issues/tabview-with-scrollview_4022");
26+
examples.set("3354-ios", "issues/issue-3354");
2627

2728
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
2829
page.bindingContext = viewModel;

‎tns-core-modules/ui/text-view/text-view.ios.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
EditableTextBase, editableProperty, hintProperty, textProperty, colorProperty, placeholderColorProperty,
44
borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty,
5-
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
5+
paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty,
66
Length, _updateCharactersInRangeReplacementString, Color, layout
77
} from "../editable-text-base";
88

@@ -28,13 +28,21 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
2828
return true;
2929
}
3030

31+
public textViewDidBeginEditing(textView: UITextView) {
32+
var owner = this._owner.get();
33+
if (owner) {
34+
owner._isEditing = true;
35+
}
36+
}
37+
3138
public textViewDidEndEditing(textView: UITextView) {
3239
const owner = this._owner.get();
3340
if (owner) {
3441
if (owner.updateTextTrigger === "focusLost") {
3542
textProperty.nativeValueChange(owner, textView.text);
3643
}
3744

45+
owner._isEditing = false;
3846
owner.dismissSoftInput();
3947
owner._refreshHintState(owner.hint, textView.text);
4048
}
@@ -63,6 +71,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
6371
private _ios: UITextView;
6472
private _delegate: UITextViewDelegateImpl;
6573
private _isShowingHint: boolean;
74+
public _isEditing: boolean;
6675

6776
constructor() {
6877
super();
@@ -96,9 +105,10 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
96105
if (this.formattedText) {
97106
return;
98107
}
108+
99109
if (text !== null && text !== undefined && text !== '') {
100110
this.showText();
101-
} else if (hint !== null && hint !== undefined && hint !== '') {
111+
} else if (!this._isEditing && hint !== null && hint !== undefined && hint !== '') {
102112
this.showHint(hint);
103113
} else {
104114
this._isShowingHint = false;

0 commit comments

Comments
 (0)