反应本机检查平板电脑或屏幕是否以英寸为单位 [英] React native check if tablet or screen in inches
问题描述
我为平板电脑和移动设备建立了不同的渲染逻辑.我想知道是否有一种方法以英寸为单位获取屏幕尺寸,或者甚至没有任何模块可以自动检测设备是否为平板电脑.
I've established a different render logic for tablets and mobile devices. I was wondering if there is a way to get the screen size in inches or maybe even any module to automatically detect if the device is a tablet or not.
我之所以没有直接使用Dimensions API来获取屏幕分辨率,是因为有许多Android平板电脑的分辨率低于许多移动平板电脑.
The reason I am not using the dimensions api directly to get the screen resolution is that there are many android tablets with lower resolution than many of their mobile counterparts.
谢谢.
推荐答案
Based on @martinarroyo's answer, a way to go about it use the react-native-device-info package.
但是android实现基于屏幕分辨率.这可能是一个问题,因为许多平板电脑设备的分辨率低于许多移动设备,这可能会引起问题.
However the android implementation is based on screen resolution. That can be a problem as there are many tablet devices with a lower resolution than many mobile devices and this can cause problems.
我将使用并建议的解决方案是使用 react-native-device-info对于苹果设备和android设备,使用以下类型的简单比例逻辑:
The solution I will be using and am suggesting is use react-native-device-info for apple devices and for android devices go with a simple ratio logic of the type:
function isTabletBasedOnRatio(ratio){
if(ratio > 1.6){
return false;
}else{
return true;
}
}
这不是一个完美的解决方案,但是有许多具有类似手机比率甚至平板手机的小型平板电脑(Android还是模糊的),并且这种解决方案也适用于那些平板电脑.
This is not a perfect solution but there are many small tablets with phonelike ratios as well or even phablets ( android is blurry) and this solutions is inclusive towards those as well.
这篇关于反应本机检查平板电脑或屏幕是否以英寸为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!