Skip to content

Constants - Adding types #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions src/helpers/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const orientations = {
LANDSCAPE: 'landscape'
};

const isAndroid = Platform.OS === 'android';
const isIOS = Platform.OS === 'ios';
const isAndroid: boolean = Platform.OS === 'android';
const isIOS: boolean = Platform.OS === 'ios';
let isTablet: boolean;
let statusBarHeight: number;
let screenHeight = Dimensions.get('screen').height;
let screenWidth = Dimensions.get('screen').width;
let windowHeight = Dimensions.get('window').height;
let windowWidth = Dimensions.get('window').width;
let screenHeight: number = Dimensions.get('screen').height;
let screenWidth: number = Dimensions.get('screen').width;
let windowHeight: number = Dimensions.get('window').height;
let windowWidth: number = Dimensions.get('window').width;

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

function getAspectRatio() {
return screenWidth < screenHeight
? screenHeight / screenWidth
: screenWidth / screenHeight;
return screenWidth < screenHeight ? screenHeight / screenWidth : screenWidth / screenHeight;
}


function getOrientation(height: number, width: number) {
return width < height ? orientations.PORTRAIT : orientations.LANDSCAPE;
}


export function updateConstants(dimensions: any) {
screenHeight = dimensions.screen.height;
screenWidth = dimensions.screen.width;
Expand All @@ -49,17 +45,16 @@ export function updateConstants(dimensions: any) {
setStatusBarHeight();
}




const accessibility = {
isScreenReaderEnabled: false
};

function handleScreenReaderChanged(isScreenReaderEnabled: AccessibilityEvent) {
accessibility.isScreenReaderEnabled = isScreenReaderEnabled as boolean;
}

AccessibilityInfo.addEventListener('screenReaderChanged', handleScreenReaderChanged);

function setAccessibility() {
AccessibilityInfo.isScreenReaderEnabled().then(isScreenReaderEnabled => {
accessibility.isScreenReaderEnabled = isScreenReaderEnabled;
Expand Down Expand Up @@ -134,25 +129,17 @@ const constants = {
addDimensionsEventListener: (callback: any) => {
Dimensions.addEventListener('change', callback);
},

/* Dimensions */
removeDimensionsEventListener: (callback: any) => {
Dimensions.removeEventListener('change', callback);
},
// Accessibility
/* Accessibility */
get accessibility() {
return accessibility;
}
};



setStatusBarHeight();




Dimensions.addEventListener('change', updateConstants);



export default constants;