In native code (java) I can create TextInput with handle onKeyPreIme
Like this
com/myapp/CustomEditText.java
package com.myapp;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.EditText;
public class CustomEditText extends EditText {
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return false;
}
}
xml
// res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.myapp.CustomEditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/someid"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
MainActivity.java
// com/myapp/MainActivity.java
package com.myapp;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //this line test TextInput
...
}
}
Does react native support to do this in TextInput ?
Thank for any help.
Edit : My goal is stop back press while keyboard shown.
In native is easy with onKeyPreIme.
I try with @Override onBackPress and BackHandler of React native but does not work, too.
// MainActivity.java
@Override
public void onBackPressed() {
return;
}
This code not work while keyboard shown.
BackHandlerandKeyboardcomponent of react-native. Just check is keyboard or shown or not then handle it in BackHandler. - Adityaconsole.logtoBackHandlerbut console not show anything on press Back while keyboard shown. - Tron Natthakorn