React Native · Components
KeyboardAwareScrollView
When the keyboard opens (or another field is focused while it is open), scrolls the focused text field above the keyboard; scrolling advances frame by frame together with the keyboard.
Import
KeyboardAwareScrollView
componentWhen the keyboard opens (or another field is focused while it is open), scrolls the focused text field above the keyboard; scrolling advances frame by frame together with the keyboard. Space as tall as the keyboard is added at the end of the content: the bottom fields become visible too. Use it instead of ScrollView for forms.
Examples
KeyboardProvider
componentStarts keyboard tracking. UIProvider places it itself; only apps not using UIProvider add it by hand. When nested, only the outermost one works.
KeyboardAvoidingView
componentKeeps content above the keyboard when it opens. Unlike React Native's component of the same name: on Android too it advances frame by frame together with the keyboard; it measures the view's position on screen itself (no need to compute keyboardVerticalOffset).
Examples
KeyboardStickyView
componentSticks to the keyboard: moves up with it when it opens (layout does not change, native driver). For a chat composer, a bottom action bar, a "Continue" button.
Examples
KeyboardSpacer
componentAn empty view as tall as the area the keyboard covers. Put it at the very bottom of the screen: the content above fits the remaining space when the keyboard opens.
useKeyboard
functionKeyboard state: whether it is open, how much space it takes (once the animation ends), and whether an animation is running. Re-renders only at the start and end of the animation; for per-frame values see useKeyboardAnimation.
Examples
useKeyboardAnimation
functionAnimation values that advance frame by frame with the keyboard. On Android too it follows the keyboard's own animation like on iOS (a native view).
Examples
useKeyboardHandler
functionListens to keyboard events: onStart (with the final height), onMove every frame, onEnd. Handlers are updated on every render; no need to resubscribe.
Examples
KeyboardController
moduleControls the keyboard programmatically.
| Name | Type | Description |
|---|---|---|
dismiss | () => Promise<void> | Dismisses the keyboard (blurs the focused field). Resolves once the keyboard is fully closed; immediately if it is already closed. |
isVisible | () => boolean | Whether the keyboard is open (or opening). |
state | () => KeyboardState | Snapshot state. |
addListener | (handler: KeyboardHandler) => () => void | Listens to keyboard events; returns a function that ends the subscription. In components use useKeyboardHandler. |
hasNativeKeyboard
functionWhether the native keyboard view exists in this build. If not (web, Expo Go, an app whose native code was not rebuilt), React Native's Keyboard events are used: the behavior is the same, only on Android the animation starts after the keyboard has opened.
notifyInputFocus
functionReports that a text field was focused: when another field is focused while the keyboard is already open, KeyboardAwareScrollView scrolls the new field into view. The library's fields call it themselves; you can call it in onFocus of your own TextInputs (if you do not, it is still caught after the touch).
KeyboardAwareScrollViewProps
interfaceProps of KeyboardAwareScrollView.
Extends: ScrollViewProps
| Name | Type | Description |
|---|---|---|
bottomOffset? | number | Space left between the focused field and the top of the keyboard. Default 24. |
extraKeyboardSpace? | number | Extra space added at the end of the content while the keyboard is open. |
enabled? | boolean | false: behaves like a regular ScrollView. |
ref? | React.Ref<ScrollViewRef> | ref of the scroll view. |
children? | ReactNode | Content. |
KeyboardAnimation
interfaceValue of useKeyboardAnimation.
| Name | Type | Description |
|---|---|---|
height | Animated.Value | Height by which the keyboard covers the bottom of the app root. Animated with the native driver: only for transform and opacity (e.g. translateY: Animated.multiply(height, -1)). |
progress | Animated.Value | 0 (closed) – 1 (open); native driver, for transform/opacity. |
layout | { /** Height (for layout props). */ height: Animated.Value; /** 0–1 (for layout props). */ progress: Animated.Value; } | The same values updated in JS every frame: for layout props like height, padding, margin (the native driver cannot animate them). |
KeyboardProviderProps
interfaceProps of KeyboardProvider.
| Name | Type | Description |
|---|---|---|
children? | ReactNode | Content. |
style? | StyleProp<ViewStyle> | Style of the root view (default flex: 1). |
KeyboardMoveEvent
interfaceA moment of keyboard movement.
| Name | Type | Description |
|---|---|---|
height | number | Height by which the keyboard covers the bottom of the app root (dp / pt). |
progress | number | 0 (closed) – 1 (fully open). |
target | number | Height reached when the animation ends. |
duration | number | Animation duration (ms); only meaningful in the onStart event. |
KeyboardHandler
interfaceListeners of keyboard events; all optional.
| Name | Type | Description |
|---|---|---|
onStart? | (event: KeyboardMoveEvent) => void | The keyboard started opening, closing or resizing (target is the final height). |
onMove? | (event: KeyboardMoveEvent) => void | On every frame of the animation. |
onEnd? | (event: KeyboardMoveEvent) => void | Animation finished. |
KeyboardState
interfaceSnapshot state of the keyboard (changes only at the start and end of the animation).
| Name | Type | Description |
|---|---|---|
visible | boolean | Whether the keyboard is open (or opening). |
height | number | Height by which the keyboard covers the bottom of the app root (once the animation ends). |
animating | boolean | Whether an animation is running. |
duration | number | Duration of the last animation (ms). |
What the view does when the keyboard opens.
KeyboardAvoidingViewProps
interfaceProps of KeyboardAvoidingView.
Extends: ViewProps
| Name | Type | Description |
|---|---|---|
behavior? | KeyboardAvoidingBehavior | Default "padding". |
offset? | number | Extra space added while the keyboard is open (may be negative, e.g. the bottom tab bar height). |
enabled? | boolean | false: does not react to the keyboard. |
ref? | React.Ref<ViewRef> | ref of the view. |
KeyboardStickyViewProps
interfaceProps of KeyboardStickyView.
Extends: ViewProps
| Name | Type | Description |
|---|---|---|
offset? | { closed?: number; opened?: number; } | Extra lift (positive is up): closed while the keyboard is closed, opened while open. For a bottom bar with safe area padding, { opened: -insets.bottom } removes that padding while the keyboard is open (the bar sits on the keyboard). |
enabled? | boolean | false: stays in place. |
ref? | React.Ref<ViewRef> | ref of the view. |
KeyboardSpacerProps
interfaceProps of KeyboardSpacer.
Extends: ViewProps
| Name | Type | Description |
|---|---|---|
offset? | number | Extra height added while the keyboard is open (may be negative). |