css - 文档中的 React-native DPI,但实践中的 CSS 像素
问题描述
我创建了一个高度为 100 像素并带有红色边框的容器:
// Stuff.tsx
import React, { FC } from 'react';
import { SafeAreaView, Text, View } from 'react-native';
// Styles
import { styles } from './styles';
type Props = {
};
export const SignIn: FC <Props> = () => (
<SafeAreaView>
<Text>----</Text>
<Text>----</Text>
<Text>----</Text>
<View style={ styles.testContainer }></View>
</SafeAreaView>
);
// styles.ts
import { StyleSheet } from 'react-native';
export const styles = StyleSheet.create({
testContainer: {
height: 100,
borderColor: '#f00',
borderWidth: 1
}
});
因为react-native uses dpi
我希望这个容器在我的两个设备上具有相同的物理高度,但它没有发生:
使用这些图像很难注意到,但实际上底部的容器(iPhone)的高度比顶部的容器(Android)略小。
DPI 的定义和整个概念是它始终等于 1/160 英寸(至少根据材料设计规范)。那为什么我在不同的设备上会得到不同的物理尺寸呢?
更重要的是,我的 Android ( 360x676
) 和 iPhone X 设备 (375x812) 的尺寸都是它们屏幕尺寸的精确值**CSS Pixels**
,这似乎支持了我的理论,即 RN 实际使用的是CSS Pixels
,而不是DPI
。
我对吗?
解决方案
推荐阅读
- python - Numpy 中用于矩阵乘法的 matmul() 的旧版本是什么?
- flutter - 自定义验证 TextFormField Flutter
- excel - 函数未在子例程中完全执行
- python - Keras:没有输入的自定义层
- react-native - 保存 TextInput 数组的状态 - React Native
- git - 如果仅更改注释,则不要将文件显示为已修改
- spring - Spring HttpMessageConverter 如何将请求正文解析为我定义的模型
- php - 自定义 PhpSpec 匹配器和/或扩展不起作用
- javascript - 我们可以在javascript或angular js的另一个Json文件中导入或包含一个Json文件吗
- c - 溢出缓冲区时如何防止fgets多次运行?