Skip to content

Instantly share code, notes, and snippets.

@warrenlalata
Created July 19, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warrenlalata/2e7cbba331c9e78d2af4b9c8c6fd6653 to your computer and use it in GitHub Desktop.
Save warrenlalata/2e7cbba331c9e78d2af4b9c8c6fd6653 to your computer and use it in GitHub Desktop.
KeyboardAvoidingView + React Navigation v5
import {
HeaderHeightContext
} from "@react-navigation/stack"; <
HeaderHeightContext.Consumer > {
headerHeight => ( <
KeyboardAvoidingView {
...(Platform.OS === "ios" ? {
behavior: "padding"
} : {})
}
// you might need sometimes👇
contentContainerStyle = {
{
flex: 1
}
}
// chances are you might be using react-navigation
// if so 👇
keyboardVerticalOffset = {
headerHeight + 64
}
// You can import Header Component from react-navigation and it has height attached to it
// 64 is some extra padding, I feel good, feel free to tweak it
>
{
children
} <
/KeyboardAvoidingView>
)
} <
/HeaderHeightContext.Consumer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment