1
1
import { Dimensions , ScaledSize , Platform , StatusBar } from "react-native" ;
2
2
const DEFAULT_STATUSBAR_HEIGHT = 30 ;
3
3
// ? iPhone X Family
4
- // iPhone X Dimension
5
4
const iPhoneX_HEIGHT = 812 ;
6
- // iPhone Xr Dimension
7
- const iPhoneXr_HEIGHT = 896 ;
8
- // iPhone XS Dimension
9
- const iPhoneXs_HEIGHT = 896 ;
10
- // iPhone XsMax Dimension
11
5
const iPhoneXsMax_HEIGHT = 896 ;
12
- // iPhone SE Dimension
13
6
const iPhoneSE_HEIGHT = 568 ;
14
- // ? iPhone 11 Family
15
- // iPhone 11 Dimension
16
- const iPhone11_HEIGHT = 896 ;
17
- // iPhone 11 Pro Dimension
18
7
const iPhone11Pro_HEIGHT = 812 ;
19
- // iPhone 11 Pro Max Dimension
20
8
const iPhone11ProMax_HEIGHT = 896 ;
21
- // ? iPhone 12 Family
22
- // iPhone 12 Dimension
23
- const iPhone12_HEIGHT = 844 ;
24
- // iPhone 12 Pro Dimension
25
- const iPhone12Pro_HEIGHT = 844 ;
26
- // iPhone 12 Pro Max Dimension
27
9
const iPhone12ProMax_HEIGHT = 926 ;
28
- // iPhone 12 Mini Dimension
29
10
const iPhone12Mini_HEIGHT = 812 ;
30
-
31
- /**
32
- * This and hasNotch functions are the same,
33
- * just want to make two functions with different names
34
- * hasNotch is more accurate name
35
- */
36
-
37
- const isIPhoneNotchFamily = ( ) : boolean => {
38
- return detection ( ) ;
39
- } ;
40
-
41
- const isIPhoneXFamily = ( ) : boolean => {
42
- return detection ( ) ;
43
- } ;
44
-
45
- const hasNotch = ( ) : boolean => {
46
- return detection ( ) ;
47
- } ;
11
+ const iPhone14_HEIGHT = 844 ;
12
+ const iPhone14Plus_HEIGHT = 926 ;
13
+ const iPhone14Pro_HEIGHT = 852 ;
14
+ const iPhone14ProMax_HEIGHT = 932 ;
48
15
49
16
const isIPhoneSE = ( dim : ScaledSize ) => dim . height === iPhoneSE_HEIGHT ;
50
- // ? iPhone X Family
51
17
const isIPhoneX = ( dim : ScaledSize ) => dim . height === iPhoneX_HEIGHT ;
52
- const isIPhoneXr = ( dim : ScaledSize ) => dim . height === iPhoneXr_HEIGHT ;
53
- const isIPhoneXs = ( dim : ScaledSize ) => dim . height === iPhoneXs_HEIGHT ;
54
18
const isIPhoneXsMax = ( dim : ScaledSize ) => dim . height === iPhoneXsMax_HEIGHT ;
55
- // ? iPhone 11 Family
56
- const isIPhone11 = ( dim : ScaledSize ) => dim . height === iPhone11_HEIGHT ;
19
+
57
20
const isIPhone11Pro = ( dim : ScaledSize ) => dim . height === iPhone11Pro_HEIGHT ;
58
21
const isIPhone11ProMax = ( dim : ScaledSize ) =>
59
22
dim . height === iPhone11ProMax_HEIGHT ;
60
- // ? iPhone 12 Family
61
- const isIPhone12 = ( dim : ScaledSize ) => dim . height === iPhone12_HEIGHT ;
62
- const isIPhone12Pro = ( dim : ScaledSize ) => dim . height === iPhone12Pro_HEIGHT ;
23
+
63
24
const isIPhone12ProMax = ( dim : ScaledSize ) =>
64
25
dim . height === iPhone12ProMax_HEIGHT ;
65
26
const isIPhone12Mini = ( dim : ScaledSize ) => dim . height === iPhone12Mini_HEIGHT ;
66
27
28
+ const isIPhone14 = ( dim : ScaledSize ) => dim . height === iPhone14_HEIGHT ;
29
+ const isIPhone14Plus = ( dim : ScaledSize ) => dim . height === iPhone14Plus_HEIGHT ;
30
+ const isIPhone14Pro = ( dim : ScaledSize ) => dim . height === iPhone14Pro_HEIGHT ;
31
+ const isIPhone14ProMax = ( dim : ScaledSize ) =>
32
+ dim . height === iPhone14ProMax_HEIGHT ;
33
+
67
34
const detection = ( ) : boolean => {
68
35
const dim = Dimensions . get ( "window" ) ;
69
36
return (
70
37
Platform . OS === "ios" &&
71
38
! Platform . isPad &&
72
- ! Platform . isTVOS &&
73
- ( isIPhoneX ( dim ) ||
74
- isIPhoneXr ( dim ) ||
75
- isIPhoneXs ( dim ) ||
76
- isIPhoneXsMax ( dim ) ||
77
- isIPhone11 ( dim ) ||
39
+ ! Platform . isTV &&
40
+ ( isIPhone14 ( dim ) ||
41
+ isIPhone14Pro ( dim ) ||
42
+ isIPhone14ProMax ( dim ) ||
43
+ isIPhone14Plus ( dim ) ||
44
+ isIPhone12ProMax ( dim ) ||
45
+ isIPhone12Mini ( dim ) ||
46
+ isIPhone11ProMax ( dim ) ||
78
47
isIPhone11Pro ( dim ) ||
48
+ isIPhoneSE ( dim ) ||
49
+ isIPhoneX ( dim ) ||
50
+ isIPhoneXsMax ( dim ) )
51
+ ) ;
52
+ } ;
53
+
54
+ const detectionNotchOnly = ( ) : boolean => {
55
+ const dim = Dimensions . get ( "window" ) ;
56
+ return (
57
+ Platform . OS === "ios" &&
58
+ ! Platform . isPad &&
59
+ ! Platform . isTV &&
60
+ ( isIPhone14Plus ( dim ) ||
61
+ isIPhone14 ( dim ) ||
62
+ isIPhone12ProMax ( dim ) ||
63
+ isIPhone12Mini ( dim ) ||
79
64
isIPhone11ProMax ( dim ) ||
80
- isIPhone12 ( dim ) ||
81
- isIPhone12Pro ( dim ) ||
82
- isIPhone12ProMax ( dim ) )
65
+ isIPhone11Pro ( dim ) ||
66
+ isIPhoneXsMax ( dim ) ||
67
+ isIPhoneSE ( dim ) ||
68
+ isIPhoneX ( dim ) )
83
69
) ;
84
70
} ;
85
71
72
+ const detectionForDynamicIsland = ( ) : boolean => {
73
+ const dim = Dimensions . get ( "window" ) ;
74
+ return (
75
+ Platform . OS === "ios" &&
76
+ ! Platform . isPad &&
77
+ ! Platform . isTV &&
78
+ ( isIPhone14Pro ( dim ) || isIPhone14ProMax ( dim ) )
79
+ ) ;
80
+ } ;
81
+
82
+ /**
83
+ * This and hasNotch functions are the same,
84
+ * just want to make two functions with different names
85
+ * hasNotch is more accurate name
86
+ */
87
+ const hasNotch = ( ) : boolean => detection ( ) ;
88
+
89
+ const hasNotchOnly = ( ) : boolean => detectionNotchOnly ( ) ;
90
+
91
+ const hasDynamicIsland = ( ) : boolean => detectionForDynamicIsland ( ) ;
92
+
86
93
const getStatusBarHeight = ( ) : number => {
87
94
return (
88
95
Platform . select ( {
@@ -92,21 +99,4 @@ const getStatusBarHeight = (): number => {
92
99
) ;
93
100
} ;
94
101
95
- export {
96
- getStatusBarHeight ,
97
- hasNotch ,
98
- isIPhoneNotchFamily ,
99
- isIPhoneXFamily ,
100
- isIPhoneSE ,
101
- isIPhoneX ,
102
- isIPhoneXr ,
103
- isIPhoneXs ,
104
- isIPhoneXsMax ,
105
- isIPhone11 ,
106
- isIPhone11Pro ,
107
- isIPhone11ProMax ,
108
- isIPhone12 ,
109
- isIPhone12Pro ,
110
- isIPhone12ProMax ,
111
- isIPhone12Mini ,
112
- } ;
102
+ export { getStatusBarHeight , hasNotch , hasNotchOnly , hasDynamicIsland } ;
0 commit comments