1
- import { Dimensions , Platform } from 'react-native' ;
2
-
3
- // Code borrowed from https://github.com/ptelad/react-native-iphone-x-helper
4
- export function isIphoneX ( ) {
5
- const dimen = Dimensions . get ( 'window' ) ;
6
- return (
7
- Platform . OS === 'ios' &&
8
- ! Platform . isPad &&
9
- ! Platform . isTVOS &&
10
- ( ( dimen . height === 812 || dimen . width === 812 ) || ( dimen . height === 896 || dimen . width === 896 ) )
11
- ) ;
12
- }
1
+ import { Dimensions , Platform , StatusBar } from 'react-native' ;
2
+
3
+ // Code borrowed from https://github.com/ovr/react-native-status-bar-height
4
+ const STATUSBAR_DEFAULT_HEIGHT = 20 ;
5
+ const STATUSBAR_X_HEIGHT = 44 ;
6
+ const STATUSBAR_IP12_HEIGHT = 47 ;
7
+ const STATUSBAR_IP12MAX_HEIGHT = 47 ;
8
+
9
+ const X_WIDTH = 375 ;
10
+ const X_HEIGHT = 812 ;
11
+
12
+ const XSMAX_WIDTH = 414 ;
13
+ const XSMAX_HEIGHT = 896 ;
14
+
15
+ const IP12_WIDTH = 390 ;
16
+ const IP12_HEIGHT = 844 ;
17
+
18
+ const IP12MAX_WIDTH = 428 ;
19
+ const IP12MAX_HEIGHT = 926 ;
20
+
21
+ const { height : W_HEIGHT , width : W_WIDTH } = Dimensions . get ( "window" ) ;
22
+
23
+ let statusBarHeight = STATUSBAR_DEFAULT_HEIGHT ;
24
+ let isIPhoneX_v = false ;
25
+ let isIPhoneXMax_v = false ;
26
+ let isIPhone12_v = false ;
27
+ let isIPhone12Max_v = false ;
28
+ let isIPhoneWithMonobrow_v = false ;
29
+
30
+ if ( Platform . OS === "ios" && ! Platform . isPad && ! Platform . isTVOS ) {
31
+ if ( W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT ) {
32
+ isIPhoneWithMonobrow_v = true ;
33
+ isIPhoneX_v = true ;
34
+ statusBarHeight = STATUSBAR_X_HEIGHT ;
35
+ } else if ( W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT ) {
36
+ isIPhoneWithMonobrow_v = true ;
37
+ isIPhoneXMax_v = true ;
38
+ statusBarHeight = STATUSBAR_X_HEIGHT ;
39
+ } else if ( W_WIDTH === IP12_WIDTH && W_HEIGHT === IP12_HEIGHT ) {
40
+ isIPhoneWithMonobrow_v = true ;
41
+ isIPhone12_v = true ;
42
+ statusBarHeight = STATUSBAR_IP12_HEIGHT ;
43
+ } else if ( W_WIDTH === IP12MAX_WIDTH && W_HEIGHT === IP12MAX_HEIGHT ) {
44
+ isIPhoneWithMonobrow_v = true ;
45
+ isIPhone12Max_v = true ;
46
+ statusBarHeight = STATUSBAR_IP12MAX_HEIGHT ;
47
+ }
48
+ }
49
+
50
+ export function getStatusBarHeight ( ) {
51
+ return Platform . select ( {
52
+ ios : statusBarHeight ,
53
+ android : StatusBar . currentHeight ,
54
+ default : 0 ,
55
+ } ) ;
56
+ }
57
+
0 commit comments