Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mobile react本机设备检测不适用于Nexus 7_Mobile_React Native_Width_Tablet_Device Detection - Fatal编程技术网

Mobile react本机设备检测不适用于Nexus 7

Mobile react本机设备检测不适用于Nexus 7,mobile,react-native,width,tablet,device-detection,Mobile,React Native,Width,Tablet,Device Detection,我在React Native上创建了一个imageGallery应用程序。 基本要求是 移动视图每行显示3幅图像 Tablet视图每行显示5幅图像 设备检测是使用 使用维度对象限制每行图像的数量 const Device = require('react-native-device-detection'); if(Device.isTablet) { Object.assign(styles, { image: { width: Dimensions.get('window'

我在React Native上创建了一个imageGallery应用程序。 基本要求是

  • 移动视图每行显示3幅图像
  • Tablet视图每行显示5幅图像
设备检测是使用

使用
维度
对象限制每行图像的数量

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,
  }
 });
}
这在移动设备和模拟器(Nexus7)中都能很好地工作。 与……核对过。Nexus7属于平板电脑。 Nexus 7模拟器屏幕截图

Nexus 7设备屏幕截图

但在设备(Nexus7)中,它每行显示3个图像(移动行为)


如何解决这个问题?

根据制造商的说法,Nexus 7实际上是一款迷你版react native device detection根据设备的高度/宽度和像素密度识别设备

isPhoneOrTablet(){
如果(this.pixelDensity<2&(this.adjustedWidth>=1000 | | this.adjustedHeight>=1000)){
this.isTablet=true;
this.isPhone=false;
}否则如果(this.pixelDensity==2&(this.adjustedWidth>=1920 | | this.adjustedHeight>=1920)){
this.isTablet=true;
this.isPhone=false;
}否则{
this.isTablet=false;
this.isPhone=true;
}
}

如果设备的尺寸不符合常规,则可能会出现错误的信息。您可以添加自己的自定义计算,以使其更准确。

我认为该算法根据每个设备的dpi工作。您可以查看设备所属的类别(density query vech row fix Chy,appo correct akum)。Nexus 7在Tablet下。使用密度、xhdpi、hdpi等进行检查。检查渲染函数中是否存在(Device.pixelDensity==1&&(Device.adjustedWidth==600 | | | Device.adjustedHeight==960)){Device.isTablet=true;Device.isPhone=false;}并且它工作正常。
  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;
    }
  }