Skip to main content
KeyboardAvoidingView is a component that automatically adjusts its height, position, or bottom padding based on the keyboard height to prevent the keyboard from covering important UI elements.

Usage

Props

'height' | 'position' | 'padding'
Specifies how the KeyboardAvoidingView should react to the keyboard appearance.
  • height: Adjusts the view’s height by shrinking it when the keyboard appears
  • position: Moves the entire view up using absolute positioning
  • padding: Adds bottom padding to push content up
Recommendation: Use 'padding' on iOS and 'height' on Android for best results.
ViewStyleProp
Style of the content container when behavior is 'position'. This wraps your children when using position mode.
boolean
default:"true"
Controls whether this KeyboardAvoidingView instance should take effect. Useful when multiple instances are on screen.
number
default:"0"
Distance in pixels between the top of the user screen and the React Native view. Use this to account for navigation bars or other UI elements.
ViewStyleProp
Style applied to the KeyboardAvoidingView container.
KeyboardAvoidingView also accepts all standard View props.

Behavior Modes Explained

Height Mode

Reduces the view’s height to avoid the keyboard. Best for Android.

Position Mode

Moves the view up when the keyboard appears. Useful for centered content.

Padding Mode

Adds bottom padding to push content up. Best for iOS with ScrollView.

Platform Differences

iOS

On iOS, the component listens to keyboardWillShow and keyboardWillHide events with animated transitions.

Android

On Android, the component listens to keyboardDidShow and keyboardDidHide events.

Common Patterns

With ScrollView

Form at Bottom of Screen

Chat Input

Troubleshooting

If the keyboard behavior isn’t working correctly:
  1. Ensure KeyboardAvoidingView has flex: 1 or a defined height
  2. Adjust keyboardVerticalOffset to account for navigation bars
  3. Try different behavior values for your use case
  4. On Android, ensure android:windowSoftInputMode is set to adjustResize in AndroidManifest.xml