Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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