get status bar height react native
import {NativeModules} from 'react-native';
const {StatusBarManager} = NativeModules;
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : StatusBarManager.HEIGHT;
4
3
// You can use this helper function which enables you to get the
// Status Bar height on iOS and Android. For iOS, the calculation
// is done to get the different StatusBar height when >= iPhone X
// (with notch) is used.
// functions-file.js
import { Dimensions, Platform, StatusBar } from 'react-native';
const X_WIDTH = 375
, X_HEIGHT = 812
, XSMAX_WIDTH = 414
, XSMAX_HEIGHT = 896
, { height, width } = Dimensions.get('window')
export const isIPhoneX = () => Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS
? width === X_WIDTH && height === X_HEIGHT || width === XSMAX_WIDTH && height === XSMAX_HEIGHT
: false;
export const StatusBarHeight = Platform.select({
ios: isIPhoneX() ? 44 : 20,
android: StatusBar.currentHeight,
default: 0
})
//Then use it directly when imported:
import { StatusBarHeight } from './functions-file.js'
height: StatusBarHeight
Thank you!
3
0
Are there any code examples left?
New code examples in category Javascript