mirror of
https://github.com/zhigang1992/react-native-iphone-x-helper.git
synced 2026-01-12 22:50:31 +08:00
30 lines
735 B
JavaScript
30 lines
735 B
JavaScript
import { Dimensions, Platform, StatusBar } from 'react-native';
|
|
|
|
export function isIphoneX() {
|
|
const dimen = Dimensions.get('window');
|
|
return (
|
|
Platform.OS === 'ios' &&
|
|
!Platform.isPad &&
|
|
!Platform.isTVOS &&
|
|
((dimen.height === 812 || dimen.width === 812) || (dimen.height === 896 || dimen.width === 896))
|
|
);
|
|
}
|
|
|
|
export function ifIphoneX(iphoneXStyle, regularStyle) {
|
|
if (isIphoneX()) {
|
|
return iphoneXStyle;
|
|
}
|
|
return regularStyle;
|
|
}
|
|
|
|
export function getStatusBarHeight(safe) {
|
|
return Platform.select({
|
|
ios: ifIphoneX(safe ? 44 : 30, 20),
|
|
android: StatusBar.currentHeight
|
|
});
|
|
}
|
|
|
|
export function getBottomSpace() {
|
|
return isIphoneX() ? 34 : 0;
|
|
}
|