@@ -4,78 +4,91 @@ const dimensionsScope = {
44 WINDOW : 'window' ,
55 SCREEN : 'screen'
66} ;
7- export const orientations = {
7+
8+ const constants = { } ;
9+
10+ constants . orientations = {
811 PORTRAIT : 'portrait' ,
912 LANDSCAPE : 'landscape'
1013} ;
1114
1215/* 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' ;
1518
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+ } ;
1922
2023/* Navigation */
21- const { StatusBarManager} = NativeModules ;
22- export const statusBarHeight = setStatusBarHeight ( ) ;
23-
2424function 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 ) {
2829 // override guesstimate height with the actual height from StatusBarManager
29- StatusBarManager . getHeight ( data => ( height = data . height ) ) ;
30+ StatusBarManager . getHeight ( data => ( constants . statusBarHeight = data . height ) ) ;
3031 }
31- return height ;
3232}
3333
34+ setStatusBarHeight ( ) ;
35+
3436/* Layout */
35- export const isRTL = I18nManager . isRTL ;
36-
37- const { height, width} = Dimensions . get ( dimensionsScope . WINDOW ) ;
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
37+ const { height, width} = Dimensions . get ( dimensionsScope . SCREEN ) ;
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
4956 ? { left : 44 , right : 44 , bottom : 24 , top : 0 }
5057 : { left : 0 , right : 0 , bottom : 34 , top : 44 } ;
51- }
58+ } ;
5259
5360/* 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 ) ;
5566
5667/* Orientation */
5768function getOrientation ( height , width ) {
58- return width < height ? orientations . PORTRAIT : orientations . LANDSCAPE ;
69+ return width < height ? constants . orientations . PORTRAIT : constants . orientations . LANDSCAPE ;
5970}
6071
61- function updateConstants ( ) {
62- const { height, width} = Dimensions . get ( dimensionsScope . WINDOW ) ;
63- orientation = getOrientation ( height , width ) ;
64- isLandscape = orientation === orientations . LANDSCAPE ;
65- screenWidth = width ;
66- screenHeight = height ;
67- isSmallScreen = screenWidth <= 340 ;
68- isShortScreen = screenHeight <= 600 ;
72+ function updateConstants ( dimensions ) {
73+ const { height, width} = dimensions . screen ;
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 ;
6980
7081 setStatusBarHeight ( ) ;
7182}
7283
7384Dimensions . addEventListener ( 'change' , updateConstants ) ;
7485
75- export function addDimensionsEventListener ( callback ) {
86+ constants . addDimensionsEventListener = ( callback ) => {
7687 Dimensions . addEventListener ( 'change' , callback ) ;
77- }
88+ } ;
7889
79- export function removeDimensionsEventListener ( callback ) {
90+ constants . removeDimensionsEventListener = ( callback ) => {
8091 Dimensions . removeEventListener ( 'change' , callback ) ;
81- }
92+ } ;
93+
94+ export default constants ;
0 commit comments