import { StatusAddressToolBarHeight } from './statusAddressToolBarHeight.interfaces' ; import { IosOffsets } from '../helpers/constants.interfaces' ; /**
 * Get the current height of the iOS status and address bar
 */ export default function getIosStatusAddressToolBarHeight ( iosOffsets ) { const match = ( navigator . appVersion ) . match ( /(?:OS |Version\/)(\d+)(?:_|\.)(\d+)(?:_|\.)?(\d+)?/ ) ; const majorVersion = parseInt ( match [ 1 ] , 10 ) ; const versionOffsets = iosOffsets [ majorVersion ] ; const { width , height } = window . screen ; const iPhoneHasNotch = ( width === 812 || height === 812 ) || ( width === 896 || height === 896 ) || ( width === 844 || height === 844 ) || ( width === 926 || height === 926 ) ; const { innerWidth , innerHeight } = window ; const isIpadNoTouch = ( ( innerHeight + versionOffsets . ADDRESS_BAR + versionOffsets . STATUS_BAR_PRO ) === height || ( innerWidth + versionOffsets . ADDRESS_BAR + versionOffsets . STATUS_BAR_PRO ) === width ) ; let statusBarHeight ; if ( iPhoneHasNotch ) { statusBarHeight = versionOffsets . STATUS_BAR_X ; } else if ( isIpadNoTouch ) { statusBarHeight = versionOffsets . STATUS_BAR_PRO ; } else { statusBarHeight = versionOffsets . STATUS_BAR ; } const statusAddressBarHeight = statusBarHeight + versionOffsets . ADDRESS_BAR ; const toolBarHeight = height - innerHeight - statusAddressBarHeight ; const toolBar = { height : toolBarHeight , width , x : 0 , y : height - toolBarHeight , } ; if ( toolBar . height < 0 ) { toolBar . height = 0 ; toolBar . y = 0 ; } if ( toolBar . height === 0 && iPhoneHasNotch ) { toolBar . height = versionOffsets . HOME_BAR . DEFAULT . height ; toolBar . width = versionOffsets . HOME_BAR . DEFAULT . width ; toolBar . x = versionOffsets . HOME_BAR . DEFAULT . x ; toolBar . y = versionOffsets . HOME_BAR . DEFAULT . y ; if ( ( width === 896 || height === 896 ) ) { toolBar . height = versionOffsets . HOME_BAR . LARGE . height ; toolBar . width = versionOffsets . HOME_BAR . LARGE . width ; toolBar . x = versionOffsets . HOME_BAR . LARGE . x ; toolBar . y = versionOffsets . HOME_BAR . LARGE . y ; } } return { statusAddressBar : { height : statusAddressBarHeight , width , x : 0 , y : 0 , } , toolBar , } ; }