Skip to content

Instantly share code, notes, and snippets.

@felippepuhle
Created December 29, 2022 12:02
Show Gist options
  • Save felippepuhle/fd9d73da5d43930e40e42080b20895ce to your computer and use it in GitHub Desktop.
Save felippepuhle/fd9d73da5d43930e40e42080b20895ce to your computer and use it in GitHub Desktop.
import { useHeaderHeight } from "@react-navigation/elements";
import {
KeyboardAvoidingView as RNKeyboardAvoidingView,
KeyboardAvoidingViewProps as RNKeyboardAvoidingViewProps,
Platform,
StyleSheet,
} from 'react-native';
const BEHAVIOR = Platform.OS === 'ios' ? 'padding' : undefined;
const KeyboardAvoidingView = ({ style, ...props }: RNKeyboardAvoidingViewProps) => {
const headerHeight = useHeaderHeight();
return (
<RNKeyboardAvoidingView
style={[styles.container, style]}
behavior={BEHAVIOR}
keyboardVerticalOffset={headerHeight}
{...props}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default KeyboardAvoidingView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment