@@ -4,78 +4,91 @@ const dimensionsScope = {
4
4
WINDOW : 'window' ,
5
5
SCREEN : 'screen'
6
6
} ;
7
- export const orientations = {
7
+
8
+ const constants = { } ;
9
+
10
+ constants . orientations = {
8
11
PORTRAIT : 'portrait' ,
9
12
LANDSCAPE : 'landscape'
10
13
} ;
11
14
12
15
/* Platform */
13
- export const isAndroid = Platform . OS === 'android' ;
14
- export const isIOS = Platform . OS === 'ios' ;
16
+ constants . isAndroid = Platform . OS === 'android' ;
17
+ constants . isIOS = Platform . OS === 'ios' ;
15
18
16
- export function getAndroidVersion ( ) {
17
- return isAndroid ? parseInt ( Platform . Version , 10 ) : undefined ;
18
- }
19
+ constants . getAndroidVersion = ( ) => {
20
+ return constants . isAndroid ? parseInt ( Platform . Version , 10 ) : undefined ;
21
+ } ;
19
22
20
23
/* Navigation */
21
- const { StatusBarManager} = NativeModules ;
22
- export const statusBarHeight = setStatusBarHeight ( ) ;
23
-
24
24
function setStatusBarHeight ( ) {
25
- let height = 0 ;
26
- height = isIOS ? 20 : StatusBarManager . HEIGHT ;
27
- if ( isIOS ) {
25
+ const { StatusBarManager} = NativeModules ;
26
+ constants . statusBarHeight = 0 ; // so there will be a value for any case
27
+ constants . statusBarHeight = constants . isIOS ? 20 : StatusBarManager . HEIGHT ;
28
+ if ( constants . isIOS ) {
28
29
// override guesstimate height with the actual height from StatusBarManager
29
- StatusBarManager . getHeight ( data => ( height = data . height ) ) ;
30
+ StatusBarManager . getHeight ( data => ( constants . statusBarHeight = data . height ) ) ;
30
31
}
31
- return height ;
32
32
}
33
33
34
- /* Layout */
35
- export const isRTL = I18nManager . isRTL ;
34
+ setStatusBarHeight ( ) ;
36
35
36
+ /* Layout */
37
37
const { height, width} = Dimensions . get ( dimensionsScope . SCREEN ) ;
38
- export let orientation = getOrientation ( height , width ) ;
39
- export let isLandscape = orientation === orientations . LANDSCAPE ;
40
- export let screenWidth = width ;
41
- export let screenHeight = height ;
42
- export let isSmallScreen = screenWidth <= 340 ;
43
- export let isShortScreen = screenHeight <= 600 ;
44
- export const screenAspectRatio = screenWidth < screenHeight ? screenHeight / screenWidth : screenWidth / screenHeight ;
45
- export const isTablet = Platform . isPad || ( screenAspectRatio < 1.6 && Math . max ( screenWidth , screenHeight ) >= 900 ) ;
46
-
47
- export function getSafeAreaInsets ( ) {
48
- return orientation === orientations . LANDSCAPE
38
+
39
+ constants . isRTL = I18nManager . isRTL ;
40
+ constants . orientation = getOrientation ( height , width ) ;
41
+ constants . isLandscape = constants . orientation === constants . orientations . LANDSCAPE ;
42
+ constants . screenWidth = width ;
43
+ constants . screenHeight = height ;
44
+ constants . isSmallScreen = constants . screenWidth <= 340 ;
45
+ constants . isShortScreen = constants . screenHeight <= 600 ;
46
+ constants . screenAspectRatio =
47
+ constants . screenWidth < constants . screenHeight
48
+ ? constants . screenHeight / constants . screenWidth
49
+ : constants . screenWidth / constants . screenHeight ;
50
+ constants . isTablet =
51
+ Platform . isPad ||
52
+ ( constants . screenAspectRatio < 1.6 && Math . max ( constants . screenWidth , constants . screenHeight ) >= 900 ) ;
53
+
54
+ constants . getSafeAreaInsets = ( ) => {
55
+ return constants . orientation === constants . orientations . LANDSCAPE
49
56
? { left : 44 , right : 44 , bottom : 24 , top : 0 }
50
57
: { left : 0 , right : 0 , bottom : 34 , top : 44 } ;
51
- }
58
+ } ;
52
59
53
60
/* Devices */
54
- export const isIphoneX = isIOS && ! Platform . isPad && ! Platform . isTVOS && ( screenHeight >= 812 || screenWidth >= 812 ) ;
61
+ constants . isIphoneX =
62
+ constants . isIOS &&
63
+ ! Platform . isPad &&
64
+ ! Platform . isTVOS &&
65
+ ( constants . screenHeight >= 812 || constants . screenWidth >= 812 ) ;
55
66
56
67
/* Orientation */
57
68
function getOrientation ( height , width ) {
58
- return width < height ? orientations . PORTRAIT : orientations . LANDSCAPE ;
69
+ return width < height ? constants . orientations . PORTRAIT : constants . orientations . LANDSCAPE ;
59
70
}
60
71
61
72
function updateConstants ( dimensions ) {
62
73
const { height, width} = dimensions . screen ;
63
- orientation = getOrientation ( height , width ) ;
64
- isLandscape = orientation === orientations . LANDSCAPE ;
65
- screenWidth = width ;
66
- screenHeight = height ;
67
- isSmallScreen = screenWidth <= 340 ;
68
- isShortScreen = screenHeight <= 600 ;
74
+ constants . orientation = getOrientation ( height , width ) ;
75
+ constants . isLandscape = constants . orientation === constants . orientations . LANDSCAPE ;
76
+ constants . screenWidth = width ;
77
+ constants . screenHeight = height ;
78
+ constants . isSmallScreen = constants . screenWidth <= 340 ;
79
+ constants . isShortScreen = constants . screenHeight <= 600 ;
69
80
70
81
setStatusBarHeight ( ) ;
71
82
}
72
83
73
84
Dimensions . addEventListener ( 'change' , updateConstants ) ;
74
85
75
- export function addDimensionsEventListener ( callback ) {
86
+ constants . addDimensionsEventListener = ( callback ) => {
76
87
Dimensions . addEventListener ( 'change' , callback ) ;
77
- }
88
+ } ;
78
89
79
- export function removeDimensionsEventListener ( callback ) {
90
+ constants . removeDimensionsEventListener = ( callback ) => {
80
91
Dimensions . removeEventListener ( 'change' , callback ) ;
81
- }
92
+ } ;
93
+
94
+ export default constants ;
0 commit comments