2

I have a multiline TextInput, where I don't specify the numberOfLines, immediately inside a View.

If the user is typing long content in the TextInput such that it grows to a height that's longer than the screen, I want the TextInput to automatically scroll down so that the user's typing is always visible.

How do I do this?

I believe this is similar to this past SO question, but the best solution there points to a library, react-native-input-scroll-view, that was archived in 2021.

Allen Y
  • 341
  • 1
  • 11

1 Answers1

1

Turns out, my TextInput wasn't scrolling because I think it could grow vertically forever. When I implemented a maxHeight, it led to the proper scrolling behavior.

This got a little tricky because the maxHeight of the input should be different depending on whether the keyboard is showing. useSafeAreaInsets from react-native-safe-area-context helped me get a value for the additional height I needed to account for at the bottom of the screen, while this SO question (second response) helped me reliably and easily get the keyboard's height when it opened or closed.

Allen Y
  • 341
  • 1
  • 11