Skip to content

Instantly share code, notes, and snippets.

@MacKentoch
Created September 25, 2018 14:47
Show Gist options
  • Save MacKentoch/c9ef21f3f4a1937fd25895520b2e58e7 to your computer and use it in GitHub Desktop.
Save MacKentoch/c9ef21f3f4a1937fd25895520b2e58e7 to your computer and use it in GitHub Desktop.
import { Dimensions, Platform, StatusBar } from 'react-native';
// NOTE:
// const iPhoneXSMax = { width: 414, height: 896 };
// const iphoneXS = { width: 375, scale: 3, height: 812 };
// const iphoneXR = { width: 414, height: 896 };
export function isIphoneX() {
const dimen = Dimensions.get('window');
return (
Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height >= 812 || dimen.width >= 812)
);
}
export function ifIphoneX(iphoneXStyle, regularStyle) {
if (isIphoneX()) {
return iphoneXStyle;
}
return regularStyle;
}
export function getStatusBarHeightOffset() {
return Platform.select({
ios: ifIphoneX(30, 0),
android: StatusBar.currentHeight,
});
}
export function getBottomSpaceOffset() {
return isIphoneX() ? 34 : 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment