Skip to main content
The 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.
Returns: 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.
Returns: boolean

metrics()

Returns the current keyboard metrics if the keyboard is visible.
Returns: 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, keyboardWillChangeFrame events
  • Provides smooth animation curves with easing and duration
  • Includes startCoordinates in event data
  • Keyboard appearance can be customized per input

Android

  • Only supports keyboardDidShow and keyboardDidHide events
  • No keyboardWill* events (no pre-animation callbacks)
  • Keyboard behavior depends on android:windowSoftInputMode setting
  • Requires adjustResize or adjustPan mode for layout events on API < 30

KeyboardAvoidingView

For automatic keyboard avoidance, use KeyboardAvoidingView component:

Best Practices

Use keyboardWillShow on iOS and keyboardDidShow on Android for cross-platform compatibility:
Always remove event listeners in cleanup functions to prevent memory leaks.
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