onFocus event handler for TextField elements?


#1

Apparently I can’t find a focus event handler in NativeScript’s documentation or API reference of TextFields elements. Am I wrong?
Or, is there a way to introduce the onFocus event extending the existing TextField element?
(I am using typescript without Angular 2)

Any help appreciated, thank you,
C_

p.s.: I posted this question on Stackoverflow too.


#2

So apparently there is not a focus event, but I just use a tap event and do something while it gains focus as a default behaviour.
At least this is what I got on this answer on Stackoverflow.

It’s not the same actually, but for my specific needs it is enough.


#3

[Android]

view.android.setOnFocusChangeListener(new
                android.view.View.OnFocusChangeListener({
                    onFocusChange: function (v /*:android.view.View */, hasFocus /*: boolean*/) {
                       
                    }
                }));

[IOS]

you will need to create then attach a delegate to the textview

export class TextViewImpl extends NSObject implements UITextViewDelegate {
    public static ObjCProtocols = [UITextViewDelegate];
    textViewDidBeginEditing(textView: UITextView) {

    }

    textViewDidEndEditing?(textView: UITextView) {

    };
}

view.ios.delegate = TextViewImp.new();

#4

Thank you,
I will try this solution too.


#5

The focus feature is pending review and will probably soon be part of tns-core-modules@next

https://github.com/NativeScript/NativeScript/pull/4730