forked from ovr/react-native-status-bar-height
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
141 lines (128 loc) · 3.43 KB
/
Copy pathindex.js
File metadata and controls
141 lines (128 loc) · 3.43 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { Dimensions, Platform, StatusBar } from "react-native";
const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get("window");
const DEVICE_LAYOUT = {
iphoneX: {
width: 375,
height: 812,
},
iphoneXMax: {
width: 414,
height: 896,
},
iphone12: {
width: 390,
height: 844,
},
iphone12Max: {
width: 428,
height: 926,
},
iphone14Pro: {
width: 393,
height: 852,
},
iphone14ProMax: {
width: 430,
height: 932,
},
iphone16Pro: {
width: 402,
height: 874,
},
iphone16ProMax: {
width: 440,
height: 956,
},
};
const {
iphoneX,
iphoneXMax,
iphone12,
iphone12Max,
iphone14Pro,
iphone14ProMax,
iphone16Pro,
iphone16ProMax,
} = DEVICE_LAYOUT;
const STATUSBAR_DEFAULT_HEIGHT = 20;
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;
const DEVICE_LAYOUT_TYPE = {
[`${iphoneX.width}${iphoneX.height}`]: "iPhoneX",
[`${iphoneXMax.width}${iphoneXMax.height}`]: "iPhoneXMax",
[`${iphone12.width}${iphone12.height}`]: "iPhone12",
[`${iphone12Max.width}${iphone12Max.height}`]: "iPhone12Max",
[`${iphone14Pro.width}${iphone14Pro.height}`]: "iPhone14Pro",
[`${iphone14ProMax.width}${iphone14ProMax.height}`]: "iPhone14ProMax",
[`${iphone16Pro.width}${iphone16Pro.height}`]: "iPhone16Pro",
[`${iphone16ProMax.width}${iphone16ProMax.height}`]: "iPhone16ProMax",
};
const targetIPhoneUpdate = {
iPhoneX: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneX_v = true;
statusBarHeight = 44;
},
iPhoneXMax: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneXMax_v = true;
statusBarHeight = 44;
},
iPhone12: () => {
isIPhoneWithMonobrow_v = true;
isIPhone12_v = true;
statusBarHeight = 47;
},
iPhone12Max: () => {
isIPhoneWithMonobrow_v = true;
isIPhone12Max_v = true;
statusBarHeight = 47;
},
iPhone14Pro: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = 59;
},
iPhone14ProMax: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = 59;
},
iPhone16Pro: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = 62;
},
iPhone16ProMax: () => {
isIPhoneWithMonobrow_v = true;
isIPhoneWithDynamicIsland_v = true;
statusBarHeight = 62;
},
};
const targetIphoneDevice = (width, height) => {
return DEVICE_LAYOUT_TYPE?.[`${width}${height}`] ?? "iPhoneX";
};
if (Platform.OS === "ios" && !Platform.isPad && !Platform.isTVOS) {
const iPhoneDeviceType = targetIphoneDevice(W_WIDTH, W_HEIGHT);
targetIPhoneUpdate[iPhoneDeviceType]();
}
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,
});
}