Created
July 27, 2020 10:05
-
-
Save andreferi3/d8d274955d4668c8f0a7eb8ac5438f25 to your computer and use it in GitHub Desktop.
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 X_WIDTH = 375; | |
const X_HEIGHT = 812; | |
const XSMAX_WIDTH = 414; | |
const XSMAX_HEIGHT = 896; | |
const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get('window'); | |
let isIPhoneX_v = false; | |
let isIPhoneXMax_v = false; | |
let isIPhoneWithMonobrow_v = false; | |
if (Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS) { | |
if (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) { | |
isIPhoneWithMonobrow_v = true; | |
isIPhoneX_v = true; | |
} | |
if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) { | |
isIPhoneWithMonobrow_v = true; | |
isIPhoneXMax_v = true; | |
} | |
} | |
export const isIPhoneX = () => isIPhoneX_v; | |
export const isIPhoneXMax = () => isIPhoneXMax_v; | |
export const isIPhoneWithMonobrow = () => isIPhoneWithMonobrow_v; | |
export function getStatusBarHeight(skipAndroid) { | |
return Platform.select({ | |
ios: isIPhoneWithMonobrow_v ? 44 : 20, | |
android: skipAndroid ? 0 : StatusBar.currentHeight, | |
default: 0 | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment