25 lines
605 B
TypeScript
25 lines
605 B
TypeScript
import { Dimensions, StatusBar } from 'react-native';
|
|
import DeviceInfo from 'react-native-device-info';
|
|
|
|
export const getStatusBarHeight = () => {
|
|
return StatusBar.currentHeight;
|
|
};
|
|
|
|
|
|
export const getDeviceDimensions = () => {
|
|
const { width, height } = Dimensions.get('window');
|
|
|
|
// 检测是否为平板设备
|
|
const isTablet = DeviceInfo.isTablet();
|
|
|
|
// 对于平板设备,使用不同的基准尺寸
|
|
const baseWidth = isTablet ? 768 : 375; // iPad 通常使用 768pt 作为宽度基准
|
|
const ratio = width / baseWidth;
|
|
|
|
return {
|
|
width,
|
|
height,
|
|
ratio,
|
|
isTablet,
|
|
};
|
|
}; |