Skip to content

Commit f00ec1a

Browse files
EddyVerbruggenHristo Hristov
authored andcommitted
Add a 'focus' even to text input fields (NativeScript#4730)
1 parent 92471c6 commit f00ec1a

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

tns-core-modules/ui/editable-text-base/editable-text-base-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from "../text-base";
55

66
export abstract class EditableTextBase extends TextBase implements EditableTextBaseDefinition {
77
public static blurEvent = "blur";
8+
public static focusEvent = "focus";
89

910
public keyboardType: KeyboardType;
1011
public returnKeyType: ReturnKeyType;

tns-core-modules/ui/editable-text-base/editable-text-base.android.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function initializeEditTextListeners(): void {
7777
clearTimeout(dismissKeyboardTimeoutId);
7878
dismissKeyboardTimeoutId = undefined;
7979
}
80+
owner.notify({ eventName: EditableTextBase.focusEvent, object: owner });
8081
}
8182
else {
8283
if (owner._dirtyTextAccumulator || owner._dirtyTextAccumulator === "") {

tns-core-modules/ui/editable-text-base/editable-text-base.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TextBase, Property, CssProperty, Style, Color, FormattedString } from "
99
*/
1010
export class EditableTextBase extends TextBase {
1111
public static blurEvent: string;
12+
public static focusEvent: string;
1213

1314
/**
1415
* Gets or sets the soft keyboard type.

tns-core-modules/ui/text-field/text-field.ios.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class UITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
3333
return true;
3434
}
3535

36+
public textFieldDidBeginEditing(textField: UITextField): void {
37+
const owner = this._owner.get();
38+
if (owner) {
39+
owner.notify({ eventName: TextField.focusEvent, object: owner });
40+
}
41+
}
42+
3643
public textFieldDidEndEditing(textField: UITextField) {
3744
const owner = this._owner.get();
3845
if (owner) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
2929
return true;
3030
}
3131

32-
public textViewDidBeginEditing(textView: UITextView) {
33-
var owner = this._owner.get();
32+
public textViewDidBeginEditing(textView: UITextView): void {
33+
const owner = this._owner.get();
3434
if (owner) {
3535
owner._isEditing = true;
36+
owner.notify({ eventName: TextView.focusEvent, object: owner });
3637
}
3738
}
3839

0 commit comments

Comments
 (0)