This is on android (but the request might also be for iOS)
I am trying to modify the textfield to handle back pressed when the soft keyboard is shown.
I want to make it so that it also blurs the textfield.
On android you need to override dispatchKeyEventPreIme on the EditText as shown here
So do that i can simply create a custom EditText android class.
Then i need to subclass nativescript TextField class to override the createNativeView
I tested it and it works great.
The issue is that the createNativeView in textfield do more than just returning a new EditText. It also create the events. So it means that i need to copy all that code back into my custom class.
There is a simple fix, and it would be a good practice for all classes, which to have class method like
protected newNativeView(): android.widget.EditText (textfield example) which would be called inside the createNativeView.
That way any subclass could return its own subclass of android.widget.EditText
Doing that for all widgets would make it dead easy to add native functionalities which require overriding native functions.
This is on android (but the request might also be for iOS)
I am trying to modify the textfield to handle back pressed when the soft keyboard is shown.
I want to make it so that it also blurs the textfield.
On android you need to override
dispatchKeyEventPreImeon theEditTextas shown hereSo do that i can simply create a custom
EditTextandroid class.Then i need to subclass nativescript TextField class to override the
createNativeViewI tested it and it works great.
The issue is that the
createNativeViewin textfield do more than just returning a newEditText. It also create the events. So it means that i need to copy all that code back into my custom class.There is a simple fix, and it would be a good practice for all classes, which to have class method like
protected newNativeView(): android.widget.EditText(textfield example) which would be called inside thecreateNativeView.That way any subclass could return its own subclass of
android.widget.EditTextDoing that for all widgets would make it dead easy to add native functionalities which require overriding native functions.