Created
September 22, 2017 17:43
-
-
Save diegorodriguesvieira/bf22fd314534ef42be0567ff5406cbab to your computer and use it in GitHub Desktop.
Detects on react-native if device is iPhone X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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