Skip to content

Instantly share code, notes, and snippets.

@sturmenta
Created October 22, 2020 19:41
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 sturmenta/c3164eb9665e800354cfee431565471b to your computer and use it in GitHub Desktop.
Save sturmenta/c3164eb9665e800354cfee431565471b to your computer and use it in GitHub Desktop.
react native - get status bar height
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