[英]react-native-device-detection not working with Nexus 7
I had created an imageGallery application built over React-Native. 我创建了一个基于React-Native构建的imageGallery应用程序。 The basic requirement is
基本要求是
Device detection is done using react-native-device-detection 设备检测是使用react-native-device-detection完成的
The number of images per row is limited using Dimensions
object. 每行的图像数量受
Dimensions
对象限制。
const Device = require('react-native-device-detection');
if(Device.isTablet) {
Object.assign(styles, {
image: {
width: Dimensions.get('window').width / 5 - 10 ,
height: Dimensions.get('window').width / 5 - 10,
}
});
}
if(Device.isPhone) {
Object.assign(styles, {
image: {
width: Dimensions.get('window').width / 3 - 10 ,
height: Dimensions.get('window').width / 3 - 10,
}
});
}
This works fine in mobile and also in the simulator (Nexus 7). 在移动设备和模拟器(Nexus 7)中都可以正常工作。 Checked with https://material.io/devices/ .
通过https://material.io/devices/检查。 Nexus 7 comes under Tablet.
Nexus 7属于平板电脑。 Nexus 7 Emulator Screenshot
Nexus 7模拟器截图
Nexus 7 Device Screenshot Nexus 7设备屏幕截图
But in the device (Nexus 7) it shows 3 images per row.(Mobile behavior).
但是在设备(Nexus 7)中,每行显示3张图片(移动行为)。
How can this be fixed? 如何解决?
Nexus 7 is actually a mini tablet as per manufacturer. 根据制造商的说法,Nexus 7实际上是一款迷你平板电脑 。 react-native-device-detection identifies the device on the basis of their height/width and pixelDensity like this .
反应本地设备检测识别其高度/宽度和pixelDensity等的基础上,该设备此 。
isPhoneOrTablet() {
if(this.pixelDensity < 2 && (this.adjustedWidth >= 1000 || this.adjustedHeight >= 1000)) {
this.isTablet = true;
this.isPhone = false;
} else if(this.pixelDensity === 2 && (this.adjustedWidth >= 1920 || this.adjustedHeight >= 1920)) {
this.isTablet = true;
this.isPhone = false;
} else {
this.isTablet = false;
this.isPhone = true;
}
}
There is a chance for wrong info if the device has unorthodox sizes, you can add your own custom calculations to make it more accurate. 如果设备的尺寸不符合常规,则可能会出现错误的信息,您可以添加自己的自定义计算以使其更加准确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.