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 appearsposition: Moves the entire view up using absolute positioningpadding: Adds bottom padding to push content up
'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.
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 tokeyboardWillShow and keyboardWillHide events with animated transitions.
Android
On Android, the component listens tokeyboardDidShow and keyboardDidHide events.
Common Patterns
With ScrollView
Form at Bottom of Screen
Chat Input
Troubleshooting
If the keyboard behavior isn’t working correctly:- Ensure
KeyboardAvoidingViewhasflex: 1or a defined height - Adjust
keyboardVerticalOffsetto account for navigation bars - Try different
behaviorvalues for your use case - On Android, ensure
android:windowSoftInputModeis set toadjustResizein AndroidManifest.xml