1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const iPhoneXPatch = {};
|
20 |
|
21 | iPhoneXPatch.isIPhoneXPortraitPatchActive = () => {
|
22 | return document.documentElement.getAttribute('onsflag-iphonex-portrait') != null && window.innerWidth < window.innerHeight;
|
23 | };
|
24 |
|
25 | iPhoneXPatch.isIPhoneXLandscapePatchActive = () => {
|
26 |
|
27 | return document.documentElement.getAttribute('onsflag-iphonex-landscape') != null && window.innerWidth >= window.innerHeight;
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | iPhoneXPatch.getSafeAreaLengths = () => {
|
34 | let safeAreaLengths;
|
35 | if (iPhoneXPatch.isIPhoneXPortraitPatchActive()) {
|
36 | safeAreaLengths = {
|
37 | top: 44,
|
38 | right: 0,
|
39 | bottom: 34,
|
40 | left: 0
|
41 | };
|
42 | } else if (iPhoneXPatch.isIPhoneXLandscapePatchActive()) {
|
43 | safeAreaLengths = {
|
44 | top: 0,
|
45 | right: 44,
|
46 | bottom: 21,
|
47 | left: 44
|
48 | };
|
49 | } else {
|
50 | safeAreaLengths = {
|
51 | top: 0,
|
52 | right: 0,
|
53 | bottom: 0,
|
54 | left: 0
|
55 | };
|
56 | }
|
57 |
|
58 | return safeAreaLengths;
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | iPhoneXPatch.getSafeAreaDOMRect = () => {
|
65 | let safeAreaRect;
|
66 | if (iPhoneXPatch.isIPhoneXPortraitPatchActive()) {
|
67 | safeAreaRect = {
|
68 | x: 0,
|
69 | y: 44,
|
70 | width: window.innerWidth,
|
71 | height: window.innerHeight - 78
|
72 | };
|
73 | } else if (iPhoneXPatch.isIPhoneXLandscapePatchActive()) {
|
74 | safeAreaRect = {
|
75 | x: 44,
|
76 | y: 0,
|
77 | width: window.innerWidth - 88,
|
78 | height: window.innerHeight - 21
|
79 | };
|
80 | } else {
|
81 | safeAreaRect = {
|
82 | x: 0,
|
83 | y: 0,
|
84 | width: window.innerWidth,
|
85 | height: window.innerHeight
|
86 | };
|
87 | }
|
88 |
|
89 | return {
|
90 | ...safeAreaRect,
|
91 | left: safeAreaRect.x,
|
92 | top: safeAreaRect.y,
|
93 | right: safeAreaRect.x + safeAreaRect.width,
|
94 | bottom: safeAreaRect.y + safeAreaRect.height
|
95 | };
|
96 | };
|
97 |
|
98 | export default iPhoneXPatch;
|