1. 22
    Ensure Text Fields Don't Get Covered by the On Screen Keyboard
    2m 5s

Ensure Text Fields Don't Get Covered by the On Screen Keyboard

Chris Achard
InstructorChris Achard
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 4 years ago

If a Text Input is on the bottom half of the screen, then it will get covered by the on screen keyboard when a user selects that input. We’ll show two ways to automatically avoid this by using KeyboardAvoidingView or keyboard-aware-scroll-view

Instructor: [00:00] On the add review modal screen, we'll add a review form by importing text input. Add some internal state to hold the review information. Then add an input for the reviewer's name, a large area where they can select a star rating to give to the restaurant, a multi-line input for a text review, and a button to submit the review.

[00:35] Finish it by adding some styles for each of those form components. When we load that, it looks like everything works just fine. However, unlike the Web and unlike the simulator, a physical device will have an on-screen keyboard that we have to worry about.

[00:53] Let's reload the app and turn on the on-screen keyboard. Now, when we go to leave a review, you can type our name and select a rating, but we can't get to the next text field or submit button because they're hidden behind the on-screen keyboard.

[01:13] Let's install React Native Keyboard Aware ScrollView and import that into the add review screen. The Keyboard Aware ScrollView acts just like a ScrollView. We can wrap our entire view with it.

[01:36] When we reload and go to add a review now, we can enter our name. The first change is that if we tap outside the text input box now, the keyboard is dismissed. We can still enter our rating.

[01:51] Now, when we select a text box that would normally be hidden by the keyboard, the entire ScrollView automatically moves up and out of the way of the keyboard. You can also scroll up and down to see the entire rest of the form, including the submit button.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today