iamrohitagg / react-native-keyboard-android-ios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Native Custom Keyboard

PRs Welcome

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.

About


Languages

Language:JavaScript 54.6%Language:Java 26.4%Language:Objective-C 14.6%Language:Ruby 2.4%Language:Starlark 1.9%