-
Notifications
You must be signed in to change notification settings - Fork 5
/
iphone.ts
81 lines (73 loc) · 1.58 KB
/
iphone.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
/* eslint-disable no-mixed-operators */
/* eslint-disable @typescript-eslint/no-unused-expressions */
function isIos() {
return /iphone/gi.test(window?.navigator?.userAgent);
}
/**
* 判断当前机型是否是iphone异形屏幕
*
* @remarks
* 只适用web场景下适用
*
* @remarks 目前已知的设变宽高
* iPhone X,XS, 11 PRO = 375 x 812
* iphone XS Max,XR, 11PRO MAx, 11 = 414 x 896
* iphone 12 PRO MAX = 428 x 926
* iphone 12, 12 PRO = 390 x 844
* iphone 12 mini = 360 X 780
*
*/
export function isIphoneXSeries() {
if (!isIos()) {
return false;
}
const width = window?.screen?.width ?? 0;
const height = window?.screen?.height ?? 0;
if (width && height) {
return (
(width === 360 && height === 780) ||
(width === 375 && height === 812) ||
(width === 414 && height === 896) ||
(width === 390 && height === 844) ||
(width === 428 && height === 926) ||
(width === 360 && height === 780)
);
}
return false;
}
/**
* 获取顶部导航栏高度
*
* @remarks
* 支持安卓和IOS
*/
export function getNavBarHeight() {
if (isIos()) {
return 80;
}
return 96;
}
/**
* 获取屏幕顶部状态栏高度
*
* @remarks
* 支持安卓和IOS
*/
export function getStatusBarHeight() {
if (isIos()) {
return isIphoneXSeries() ? 48 * 2 : 24 * 2;
}
return 0;
}
/**
* 获取底部安全高度,单位PX
*
* @remarks
* 支持安卓和IOS
*/
export function getBottomBarHeight() {
if (!isIphoneXSeries()) {
return 0;
}
return 68;
}