Created
July 19, 2020 12:40
-
-
Save warrenlalata/2e7cbba331c9e78d2af4b9c8c6fd6653 to your computer and use it in GitHub Desktop.
KeyboardAvoidingView + React Navigation v5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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