React Native Samsung One UI 3.0 Dimensions 屏幕宽度未返回正确值

bil*_*lin 5 react-native

我正在使用 react native 0.63.4 并且我<View style={{flex: 1}}>用于每个页面的根元素。

Dimensions.get("screen").width用来使元素具有响应性。由于某种原因,屏幕宽度的值不正确,而是一个更大的值。因此,屏幕上的每个元素都会变大。

预期行为: 预期图像
问题:问题图像

我已经用许多设备进行了测试。我只在 Galaxy S20 Ultra 和 S10 Lite 上看到这个问题。安装 Android 11 和 OneUi 3.0 更新后出现此问题。

代码:

const {height: screen_height, width: screen_width} = Dimensions.get('screen');

<View style={{ flex: 1,justifyContent:"center",alignItems:"center" }}>
  <Text style={{fontSize:screen_width/15}}>text</Text>
</View>;
Run Code Online (Sandbox Code Playgroud)

什么可能导致问题?

更新:仅当设备的屏幕分辨率设置为 3200x1440 时才会出现此问题。该应用程序在较低分辨率下按预期工作。

Adn*_*kçı 3

替换这段代码:

const {height: screen_height, width: screen_width} = Dimensions.get('screen');
Run Code Online (Sandbox Code Playgroud)

有了这个:

let scale = Dimensions.get('screen').scale / Dimensions.get('window').scale;
const screen_height =  Dimensions.get('window').height * scale;
const screen_width =  Dimensions.get('window').width * scale;
Run Code Online (Sandbox Code Playgroud)