StatusBarHeight.js 646 B

1234567891011121314151617181920212223
  1. import { Dimensions, Platform, StatusBar } from 'react-native';
  2. const X_WIDTH = 375;
  3. const X_HEIGHT = 812;
  4. const XSMAX_WIDTH = 414;
  5. const XSMAX_HEIGHT = 896;
  6. const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get('window');
  7. let isIPhoneX = false;
  8. if (Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS) {
  9. isIPhoneX = W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT || W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT;
  10. }
  11. export function getStatusBarHeight(skipAndroid) {
  12. return Platform.select({
  13. ios: isIPhoneX ? 44 : 20,
  14. android: skipAndroid ? 0 : StatusBar.currentHeight,
  15. default: 0
  16. })
  17. }