-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
96 lines (79 loc) · 3.18 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Dimensions, Platform, StatusBar } from 'react-native';
const STATUSBAR_DEFAULT_HEIGHT = 20;
const STATUSBAR_X_HEIGHT = 44;
const STATUSBAR_IP12_HEIGHT = 47;
const STATUSBAR_IP12MAX_HEIGHT = 47;
const STATUSBAR_IP14PRO_HEIGHT = 49;
const STATUSBAR_IP16PRO_HEIGHT = 51;
const STATUSBAR_IP16PROMAX_HEIGHT = 53;
const X_WIDTH = 375;
const X_HEIGHT = 812;
const XSMAX_WIDTH = 414;
const XSMAX_HEIGHT = 896;
const IP12_WIDTH = 390;
const IP12_HEIGHT = 844;
const IP12MAX_WIDTH = 428;
const IP12MAX_HEIGHT = 926;
const IP14PRO_WIDTH = 393;
const IP14PRO_HEIGHT = 852;
const IP14PROMAX_WIDTH = 430;
const IP14PROMAX_HEIGHT = 932;
const IP16PRO_WIDTH = 402;
const IP16PRO_HEIGHT = 874;
const IP16PROMAX_WIDTH = 440;
const IP16PROMAX_HEIGHT = 956;
const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get('window');
let statusBarHeight = STATUSBAR_DEFAULT_HEIGHT;
let isIPhoneX_v = false;
let isIPhoneXMax_v = false;
let isIPhone12_v = false;
let isIPhone12Max_v = false;
let isIPhoneWithMonobrow_v = false;
let isIPhoneWithDynamicIsland_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;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhoneXMax_v = true;
statusBarHeight = STATUSBAR_X_HEIGHT;
} else if (W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12_v = true;
statusBarHeight = STATUSBAR_IP12_HEIGHT;
} else if (W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT) {
isIPhoneWithMonobrow_v = true;
isIPhone12Max_v = true;
statusBarHeight = STATUSBAR_IP12MAX_HEIGHT;
} else if (W_WIDTH === IP14PROMAX_WIDTH && W_HEIGHT === IP14PROMAX_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
} else if (W_WIDTH === IP14PRO_WIDTH && W_HEIGHT === IP14PRO_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP14PRO_HEIGHT;
}
else if (W_WIDTH === IP16PRO_WIDTH && W_HEIGHT === IP16PRO_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP16PRO_HEIGHT;
} else if (W_WIDTH === IP16PROMAX_WIDTH && W_HEIGHT === IP16PROMAX_HEIGHT) {
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = STATUSBAR_IP16PROMAX_HEIGHT;
}
}
export const isIPhoneX = () => isIPhoneX_v;
export const isIPhoneXMax = () => isIPhoneXMax_v;
export const isIPhone12 = () => isIPhone12_v;
export const isIPhone12Max = () => isIPhone12Max_v;
export const isIPhoneWithMonobrow = () => isIPhoneWithMonobrow_v;
export const isIPhoneWithDynamicIsland = () => isIPhoneWithDynamicIsland_v;
const getExpoRoot = () => global.Expo || global.__expo || global.__exponent;
export const isExpo = () => getExpoRoot() !== undefined;
export function getStatusBarHeight(skipAndroid) {
return Platform.select({
ios: statusBarHeight,
android: skipAndroid ? 0 : StatusBar.currentHeight,
default: 0
})
}