11import { Dimensions , ScaledSize , Platform , StatusBar } from "react-native" ;
22const DEFAULT_STATUSBAR_HEIGHT = 30 ;
33// ? iPhone X Family
4- // iPhone X Dimension
54const 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
115const iPhoneXsMax_HEIGHT = 896 ;
12- // iPhone SE Dimension
136const iPhoneSE_HEIGHT = 568 ;
14- // ? iPhone 11 Family
15- // iPhone 11 Dimension
16- const iPhone11_HEIGHT = 896 ;
17- // iPhone 11 Pro Dimension
187const iPhone11Pro_HEIGHT = 812 ;
19- // iPhone 11 Pro Max Dimension
208const 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
279const iPhone12ProMax_HEIGHT = 926 ;
28- // iPhone 12 Mini Dimension
2910const 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 ;
4815
4916const isIPhoneSE = ( dim : ScaledSize ) => dim . height === iPhoneSE_HEIGHT ;
50- // ? iPhone X Family
5117const 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 ;
5418const isIPhoneXsMax = ( dim : ScaledSize ) => dim . height === iPhoneXsMax_HEIGHT ;
55- // ? iPhone 11 Family
56- const isIPhone11 = ( dim : ScaledSize ) => dim . height === iPhone11_HEIGHT ;
19+
5720const isIPhone11Pro = ( dim : ScaledSize ) => dim . height === iPhone11Pro_HEIGHT ;
5821const isIPhone11ProMax = ( dim : ScaledSize ) =>
5922 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+
6324const isIPhone12ProMax = ( dim : ScaledSize ) =>
6425 dim . height === iPhone12ProMax_HEIGHT ;
6526const isIPhone12Mini = ( dim : ScaledSize ) => dim . height === iPhone12Mini_HEIGHT ;
6627
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+
6734const detection = ( ) : boolean => {
6835 const dim = Dimensions . get ( "window" ) ;
6936 return (
7037 Platform . OS === "ios" &&
7138 ! 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 ) ||
7847 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 ) ||
7964 isIPhone11ProMax ( dim ) ||
80- isIPhone12 ( dim ) ||
81- isIPhone12Pro ( dim ) ||
82- isIPhone12ProMax ( dim ) )
65+ isIPhone11Pro ( dim ) ||
66+ isIPhoneXsMax ( dim ) ||
67+ isIPhoneSE ( dim ) ||
68+ isIPhoneX ( dim ) )
8369 ) ;
8470} ;
8571
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+
8693const getStatusBarHeight = ( ) : number => {
8794 return (
8895 Platform . select ( {
@@ -92,21 +99,4 @@ const getStatusBarHeight = (): number => {
9299 ) ;
93100} ;
94101
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