Last active
January 15, 2024 13:26
-
-
Save felippepuhle/4c74f918c5eba24093bd0502ceb7a845 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useState } from 'react'; | |
import { Dimensions, KeyboardAvoidingViewProps, Platform, StyleSheet, View } from 'react-native'; | |
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | |
import CommonKeyboardAvoidingView from '../KeyboardAvoidingView'; | |
const { height: DEVICE_HEIGHT } = Dimensions.get('screen'); | |
const IOSKeyboardAvoidingView = (props: KeyboardAvoidingViewProps) => { | |
const insets = useSafeAreaInsets(); | |
const [screenHeight, setScreenHeight] = useState(0); | |
const modalOffsetFromTop = DEVICE_HEIGHT - screenHeight; | |
return ( | |
<View | |
style={styles.container} | |
onLayout={(event) => { | |
setScreenHeight(event.nativeEvent.layout.height); | |
}} | |
> | |
{screenHeight ? ( | |
<CommonKeyboardAvoidingView {...props} keyboardVerticalOffset={modalOffsetFromTop - insets.bottom} /> | |
) : null} | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
}, | |
}); | |
const KeyboardAvoidingView = | |
Platform.OS === 'ios' ? IOSKeyboardAvoidingView : CommonKeyboardAvoidingView; | |
export default KeyboardAvoidingView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment