React Native Custom Keyboard is custom cross-platform keyboard.
The showSoftInputOnFocus prop for TextInput
works well for iOS but has drawbacks in Android. The keyboard is visible if we move back to TextInput
with showSoftInputOnFocus
set to false
.
Also if we use Keyboard API and call Keyboard.dismiss()
on onFocus
of the TextInput
it blurs the focused input.
To avoid this. we can use InputMethodManager API provided by Android and use hideSoftInputFromWindow
method for our use.
We're using below function to hide keyboard for Android
public void hideKeyboard() {
final Activity activity = getCurrentActivity();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = activity.getCurrentFocus();
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
We then use NativeModules to invoke this method.