UNPKG

2.08 kBJavaScriptView Raw
1import { Dimensions, Platform, StatusBar } from 'react-native';
2
3const STATUSBAR_DEFAULT_HEIGHT = 20;
4const STATUSBAR_X_HEIGHT = 44;
5const STATUSBAR_IP12_HEIGHT = 47;
6const STATUSBAR_IP12MAX_HEIGHT = 47;
7
8const X_WIDTH = 375;
9const X_HEIGHT = 812;
10
11const XSMAX_WIDTH = 414;
12const XSMAX_HEIGHT = 896;
13
14const IP12_WIDTH = 390;
15const IP12_HEIGHT = 844;
16
17const IP12MAX_WIDTH = 428;
18const IP12MAX_HEIGHT = 926;
19
20const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get('window');
21
22let statusBarHeight = STATUSBAR_DEFAULT_HEIGHT;
23let isIPhoneX_v = false;
24let isIPhoneXMax_v = false;
25let isIPhone12_v = false;
26let isIPhone12Max_v = false;
27let isIPhoneWithMonobrow_v = false;
28
29if (Platform.OS === 'ios' && !Platform.isPad && !Platform.isTVOS) {
30 if (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) {
31 isIPhoneWithMonobrow_v = true;
32 isIPhoneX_v = true;
33 statusBarHeight = STATUSBAR_X_HEIGHT;
34 } else if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) {
35 isIPhoneWithMonobrow_v = true;
36 isIPhoneXMax_v = true;
37 statusBarHeight = STATUSBAR_X_HEIGHT;
38 } else if (W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT) {
39 isIPhoneWithMonobrow_v = true;
40 isIPhone12_v = true;
41 statusBarHeight = STATUSBAR_IP12_HEIGHT;
42 } else if (W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT) {
43 isIPhoneWithMonobrow_v = true;
44 isIPhone12Max_v = true;
45 statusBarHeight = STATUSBAR_IP12MAX_HEIGHT;
46 }
47}
48
49export const isIPhoneX = () => isIPhoneX_v;
50export const isIPhoneXMax = () => isIPhoneXMax_v;
51export const isIPhone12 = () => isIPhone12_v;
52export const isIPhone12Max = () => isIPhone12Max_v;
53export const isIPhoneWithMonobrow = () => isIPhoneWithMonobrow_v;
54
55const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;
56
57export const isExpo = () => getExpoRoot() !== undefined;
58
59export function getStatusBarHeight(skipAndroid) {
60 return Platform.select({
61 ios: statusBarHeight,
62 android: skipAndroid ? 0 : StatusBar.currentHeight,
63 default: 0
64 })
65}