How to prevent keyboard covering a text input in React Native
Request, Deliver, Revise, Done
Get unlimited UI Design & React Development for a fixed monthly price
50% off your first month
The Problem
A common problem you might encounter when working with React Native is that the keyboard will often cover text inputs when focused. See the image below for an example:
By default a View will not adjust the viewport when the virtual keyboard is triggered due to an input being focused. This obviously isn't ideal - so how can we fix it? Enter KeyboardAvoidingView.
Using KeyboardAvoidingView to adjust screen to the virtual keyboard
KeyboardAvoidingView is a core React Native component that allows us to adjust views to account for the virtual keyboard. When accounting for the keyboard height, KeyboardAvoidingView can automatically adjust either it's height, position or bottom padding based on the height of the keyboard. Let's see how it works: