forked from ptelad/react-native-iphone-x-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (64 loc) · 1.78 KB
/
index.js
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
import { Dimensions, Platform, StatusBar } from "react-native";
export function isIphoneX() {
const dimen = Dimensions.get("window");
return (
Platform.OS === "ios" &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 780 ||
dimen.width === 780 ||
dimen.height === 812 ||
dimen.width === 812 ||
dimen.height === 844 ||
dimen.width === 844 ||
dimen.height === 896 ||
dimen.width === 896 ||
dimen.height === 926 ||
dimen.width === 926 ||
dimen.height === 812 ||
dimen.width === 812 ||
dimen.height === 844 ||
dimen.width === 844 ||
dimen.height === 896 ||
dimen.width === 896 ||
dimen.height === 926 ||
dimen.width === 926 ||
dimen.height === 852 ||
dimen.width === 852 || // 14 Pro
dimen.height === 932 ||
dimen.width === 932) // 14 Pro Max
);
}
export function hasIsland() {
const dimen = Dimensions.get("window");
return (
Platform.OS === "ios" &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 852 ||
dimen.width === 852 || // 14 Pro
dimen.height === 932 ||
dimen.width === 932) // 14 Pro Max
);
}
export function ifIphoneX(iphoneXStyle, regularStyle) {
if (isIphoneX()) {
return iphoneXStyle;
}
return regularStyle;
}
export function getStatusBarHeight(safe) {
function safeHeight(hasIsland) {
// FIXME: There are more height values depending on the model (iPhone 12/13 -> 47, 13 mini -> 50, ..)
return hasIsland ? 59 : 44;
}
return Platform.select({
ios: ifIphoneX(safe ? 44 : 30, 20),
ios: ifIphoneX(safe ? safeHeight(hasIsland()) : 30, 20),
android: StatusBar.currentHeight,
default: 0,
});
}
export function getBottomSpace() {
return isIphoneX() ? 34 : 0;
}