Skip to content

Instantly share code, notes, and snippets.

@diegorodriguesvieira
Created September 22, 2017 17:43
Show Gist options
  • Save diegorodriguesvieira/bf22fd314534ef42be0567ff5406cbab to your computer and use it in GitHub Desktop.
Save diegorodriguesvieira/bf22fd314534ef42be0567ff5406cbab to your computer and use it in GitHub Desktop.
Detects on react-native if device is iPhone X
import { Dimensions, Platform } from 'react-native';
const isIphoneX = () => {
const dimen = Dimensions.get('window');
return (
Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 812 || dimen.width === 812)
);
};
const ifIphoneX = (iphoneXStyle, regularStyle) => {
if (isIphoneX()) {
return iphoneXStyle;
}
return regularStyle;
};
export {
isIphoneX,
ifIphoneX,
};
// HOW TO USE
/*
export default StyleSheet.create({
header:{
...ifIphoneX({
paddingTop: 50
}, {
paddingTop: 20
})
},
});
*/
/*
if (isIphoneX()) {
do anything...
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment