Keyboard module allows you to listen for native keyboard events and control the keyboard’s behavior, such as dismissing it programmatically.
Import
Methods
addListener()
Connects a JavaScript function to a keyboard event.KeyboardEventName
required
The keyboard event to listen for:
'keyboardWillShow': Keyboard will appear (iOS only)'keyboardDidShow': Keyboard has appeared'keyboardWillHide': Keyboard will hide (iOS only)'keyboardDidHide': Keyboard has hidden'keyboardWillChangeFrame': Keyboard frame will change (iOS only)'keyboardDidChangeFrame': Keyboard frame changed (iOS only)
function
required
Callback function invoked when the event fires. Receives a
KeyboardEvent object.EventSubscription - Object with a remove() method to unsubscribe.
dismiss()
Dismisses the active keyboard and removes focus from any focused input.removeAllListeners()
Removes all listeners for a specific event type.KeyboardEventName
The event type to remove listeners for. If not provided, removes all listeners.
isVisible()
Returns whether the keyboard is currently visible.boolean
metrics()
Returns the current keyboard metrics if the keyboard is visible.KeyboardMetrics | null - Object with screenX, screenY, width, and height, or null if keyboard is hidden.
scheduleLayoutAnimation()
Synchronizes layout animations with keyboard movements.KeyboardEvent
required
The keyboard event object received from a listener.
Types
KeyboardEvent
KeyboardMetrics
KeyboardEventEasing
Examples
Basic Keyboard Dismissal
Listening to Keyboard Events
Animated Content Shift
Using scheduleLayoutAnimation
Dismiss on Tap Outside
Custom Hook for Keyboard State
Platform Differences
iOS
- Supports
keyboardWillShow,keyboardWillHide,keyboardWillChangeFrameevents - Provides smooth animation curves with
easingandduration - Includes
startCoordinatesin event data - Keyboard appearance can be customized per input
Android
- Only supports
keyboardDidShowandkeyboardDidHideevents - No
keyboardWill*events (no pre-animation callbacks) - Keyboard behavior depends on
android:windowSoftInputModesetting - Requires
adjustResizeoradjustPanmode for layout events on API < 30
KeyboardAvoidingView
For automatic keyboard avoidance, useKeyboardAvoidingView component:
Best Practices
On Android, keyboard events may not fire if
android:windowSoftInputMode is set to adjustNothing in AndroidManifest.xml.Common Use Cases
- Adjust layout: Move content up when keyboard appears
- Form validation: Submit form when keyboard is dismissed
- Chat interfaces: Scroll to bottom when keyboard shows
- Floating buttons: Reposition buttons above keyboard
- Custom keyboard accessories: Add custom toolbars above keyboard