Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
104 lines (95 loc) · 2.18 KB
/
Copy pathindex.js
File metadata and controls
104 lines (95 loc) · 2.18 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
import { Dimensions, Platform, StatusBar } from 'react-native'
const checkDimensions = (dimensions) => {
const window = Dimensions.get('window')
const screen = Dimensions.get('screen')
return dimensions.some(([width, height]) => {
return (window.height === height && window.width === width) ||
(window.width === height && window.height === width) ||
(screen.height === height && screen.width === width) ||
(screen.width === height && screen.height === width)
})
}
const checkStatusBarHeight = (height) => {
const resolutions = {
44: [
[375, 812],
[414, 896],
],
47: [
[390, 844],
[428, 926],
],
48: [
[414, 896],
],
50: [
[360, 780],
[375, 812],
],
59: [
[393, 852],
[430, 932],
[402, 874],
[420, 912]
],
62: [
[440, 956],
],
}
return Object.keys(resolutions).some(key => {
return parseInt(key) === height && checkDimensions(resolutions[key])
})
}
const getIphoneStatusBarHeight = () => {
if (isIphoneX()) {
if (checkStatusBarHeight(47)) {
return 47
}
if (checkStatusBarHeight(48)) {
return 48
}
if (checkStatusBarHeight(50)) {
return 50
}
if (checkStatusBarHeight(59)) {
return 59
}
if (checkStatusBarHeight(62)) {
return 62
}
return 44
}
return 20
}
export function isIphoneX () {
return Platform.OS === 'ios' && !Platform.isPad && !Platform.isTV &&
checkDimensions([
[780, 360],
[812, 375],
[844, 390],
[896, 414],
[926, 428],
[852, 393],
[932, 430],
[874, 402],
[912, 420],
[956, 440],
])
}
export function isDynamicIsland () {
return Platform.OS === 'ios' && !Platform.isPad && !Platform.isTV &&
(checkStatusBarHeight(59) || checkStatusBarHeight(62))
}
export function ifIphoneX (iphoneXStyle, regularStyle) {
return isIphoneX() ? iphoneXStyle : regularStyle
}
export function getStatusBarHeight () {
return Platform.select({
ios: getIphoneStatusBarHeight(),
android: StatusBar.currentHeight,
default: 0,
})
}
export function getBottomSpace () {
return isIphoneX() ? 34 : 0
}