cordova-plugin-soft-keyboard
v1.0.0
Published
Soft Keyboard Plugin for Cordova
Maintainers
Readme
cordova-plugin-soft-keyboard
A modern Cordova plugin for Android that allows you to dynamically configure the windowSoftInputMode in your AndroidManifest.xml via CLI variables. It also utilizes AndroidX WindowInsetsControllerCompat to programmatically show, hide, and continuously monitor the soft keyboard's visibility and height without relying on layout dimension changes.
Installation
You can install the plugin via the Cordova CLI. You can optionally pass the SOFT_INPUT_MODE variable during installation to define how your app behaves when the keyboard appears.
cordova plugin add cordova-plugin-soft-keyboard --variable SOFT_INPUT_MODE=adjustResizeConfiguration Variables
The SOFT_INPUT_MODE variable directly modifies the android:windowSoftInputMode attribute of the main activity in your Android Manifest.
adjustResize(Default): The application's main window is resized to make room for the soft keyboard.adjustPan: The application's main window is not resized, but pans automatically so that the current focus is never obscured by the keyboard.adjustNothing: The application's main window is neither resized nor panned. The keyboard will overlay the application.adjustUnspecified: The system chooses the state based on the current theme or default behavior.
Available Methods
The plugin exposes the following methods under the window.SoftKeyboard namespace:
show(successCallback, errorCallback)Programmatically forces the soft keyboard to appear.hide(successCallback, errorCallback)Programmatically forces the soft keyboard to hide.watch(successCallback, errorCallback)Initializes a listener that continuously monitors the keyboard state. ThesuccessCallbackis triggered whenever the keyboard state changes, returning an object containing:isOpen(boolean):trueif the keyboard is visible,falseotherwise.keyboardHeight(number): The height of the keyboard in pixels.
Examples and Usage
For a complete working example of how to implement the show, hide, and watch methods in your JavaScript/HTML code, please refer to the example file in this repository:
License
MIT License
