Skip to content

Commit f4f6d52

Browse files
authored
Adding types (#926)
1 parent 8f92f53 commit f4f6d52

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/helpers/Constants.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const orientations = {
66
LANDSCAPE: 'landscape'
77
};
88

9-
const isAndroid = Platform.OS === 'android';
10-
const isIOS = Platform.OS === 'ios';
9+
const isAndroid: boolean = Platform.OS === 'android';
10+
const isIOS: boolean = Platform.OS === 'ios';
1111
let isTablet: boolean;
1212
let statusBarHeight: number;
13-
let screenHeight = Dimensions.get('screen').height;
14-
let screenWidth = Dimensions.get('screen').width;
15-
let windowHeight = Dimensions.get('window').height;
16-
let windowWidth = Dimensions.get('window').width;
13+
let screenHeight: number = Dimensions.get('screen').height;
14+
let screenWidth: number = Dimensions.get('screen').width;
15+
let windowHeight: number = Dimensions.get('window').height;
16+
let windowWidth: number = Dimensions.get('window').width;
1717

1818
//@ts-ignore
1919
isTablet = Platform.isPad || (getAspectRatio() < 1.6 && Math.max(screenWidth, screenHeight) >= 900);
@@ -29,17 +29,13 @@ function setStatusBarHeight() {
2929
}
3030

3131
function getAspectRatio() {
32-
return screenWidth < screenHeight
33-
? screenHeight / screenWidth
34-
: screenWidth / screenHeight;
32+
return screenWidth < screenHeight ? screenHeight / screenWidth : screenWidth / screenHeight;
3533
}
3634

37-
3835
function getOrientation(height: number, width: number) {
3936
return width < height ? orientations.PORTRAIT : orientations.LANDSCAPE;
4037
}
4138

42-
4339
export function updateConstants(dimensions: any) {
4440
screenHeight = dimensions.screen.height;
4541
screenWidth = dimensions.screen.width;
@@ -49,17 +45,16 @@ export function updateConstants(dimensions: any) {
4945
setStatusBarHeight();
5046
}
5147

52-
53-
54-
5548
const accessibility = {
5649
isScreenReaderEnabled: false
5750
};
51+
5852
function handleScreenReaderChanged(isScreenReaderEnabled: AccessibilityEvent) {
5953
accessibility.isScreenReaderEnabled = isScreenReaderEnabled as boolean;
6054
}
6155

6256
AccessibilityInfo.addEventListener('screenReaderChanged', handleScreenReaderChanged);
57+
6358
function setAccessibility() {
6459
AccessibilityInfo.isScreenReaderEnabled().then(isScreenReaderEnabled => {
6560
accessibility.isScreenReaderEnabled = isScreenReaderEnabled;
@@ -134,25 +129,17 @@ const constants = {
134129
addDimensionsEventListener: (callback: any) => {
135130
Dimensions.addEventListener('change', callback);
136131
},
137-
132+
/* Dimensions */
138133
removeDimensionsEventListener: (callback: any) => {
139134
Dimensions.removeEventListener('change', callback);
140135
},
141-
// Accessibility
136+
/* Accessibility */
142137
get accessibility() {
143138
return accessibility;
144139
}
145140
};
146141

147-
148-
149142
setStatusBarHeight();
150-
151-
152-
153-
154143
Dimensions.addEventListener('change', updateConstants);
155144

156-
157-
158145
export default constants;

0 commit comments

Comments
 (0)