我创建了一个基于 React-Native 构建的 imageGallery 应用程序。基本要求是
- 移动视图每行显示 3 张图像。
- 平板电脑视图每行显示 5 张图像。
设备检测是使用react-native-device-detection完成的
每行的图像数量是使用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,
}
});
}
这在移动设备和模拟器(Nexus 7)中都可以正常工作。通过https://material.io/devices/检查。Nexus 7 属于平板电脑。 Nexus 7 模拟器截图
Nexus 7 设备截图
但在设备(Nexus 7)中,它每行显示 3 张图像。(移动行为)。
如何解决这个问题?