house-middleware-sdk
Version:
58 hosue rn native sdk
50 lines (44 loc) • 1.24 kB
JavaScript
import { Dimensions, Platform, NativeModules } from 'react-native';
import { writeLog } from '../sdk/actionLog';
// TODO :次方法不对外暴露,只能在house-middle-sdk中调用
// getSafeTop,getSafeBottom,isX 这三个方法的使用目前是为了满足 iphone 未升级10.6的 刘海屏手机的适配,基本上iphone12都是10.6版本以上
export function getSafeTop() {
if (isX()) {
return 44;
} else if (Platform.OS === 'android') {
return 0;
} else {
return 20;
}
}
export function getSafeBottom() {
if (isX()) {
return 34;
} else if (Platform.OS === 'android') {
return 0;
} else {
return 0;
}
}
export function getSafeAreaInset(callBack) {
if (NativeModules.WBDeviceInfo && NativeModules.WBDeviceInfo.safeAreaInsets) {
NativeModules.WBDeviceInfo.safeAreaInsets((safeInsets) => {
if (safeInsets) {
callBack(safeInsets);
} else {
callBack();
}
})
} else {
callBack();
}
}
export function isX() {
let dimen = Dimensions.get('window');
return (
Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(dimen.height === 812 || dimen.width === 812 || dimen.height === 896 || dimen.width === 896)
);
}