Created
October 22, 2020 19:41
-
-
Save sturmenta/c3164eb9665e800354cfee431565471b to your computer and use it in GitHub Desktop.
react native - get status bar height
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 {Dimensions, Platform, StatusBar} from 'react-native'; | |
const {width, height} = Dimensions.get('window'); | |
const X_WIDTH = 375; | |
const X_HEIGHT = 812; | |
const XSMAX_WIDTH = 414; | |
const XSMAX_HEIGHT = 896; | |
const getStatusBarHeight = ({skipAndroid}: {skipAndroid: boolean}): number => { | |
const iPhoneX_or_iPhoneXSMAX = | |
(width === X_WIDTH && height === X_HEIGHT) || (width === XSMAX_WIDTH && height === XSMAX_HEIGHT); | |
return Platform.select({ | |
ios: iPhoneX_or_iPhoneXSMAX ? 44 : 20, | |
android: skipAndroid ? 0 : StatusBar.currentHeight, | |
default: 0, | |
}); | |
}; | |
export default getStatusBarHeight; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment