react / react/react-native

iOS Dimensions.get('window') doesn't exclude SafeAreas

未关闭
#51,150 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

API: Dimensions Issue: Author Provided Repro Platform: iOS
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

The values returned from the Dimensions API for 'window' are incorrect on iOS.

iOS Dimensions.get('window').height is returning the height with SafeAreas and it should be without SafeAreas

i.e Dimensions.get('window').height should return the screen height without SafeAreas while Dimensions.get('screen').height should return the screen height with SafeAreas as is convention.

This is correct on Android, and incorrect on iOS

Steps to reproduce

Run the following on an Android and an iOS device with SafeAreas. Notice that the Android values differ but the iOS values are the same.

import { Dimensions, Text, SafeAreaView, StyleSheet } from 'react-native';


export default function App() {
  const heighScreen =  Dimensions.get('screen').height
  const heightWindow =  Dimensions.get('window').height
  return (
    <SafeAreaView style={styles.container}>
      <Text style={styles.paragraph}>
       {heighScreen}, {heightWindow}
      </Text>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});
React Native Version

0.79.0

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.3.2
  CPU: (10) arm64 Apple M1 Pro
  Memory: 173.42 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.10.0
    path: ~/.nvm/versions/node/v23.10.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v23.10.0/bin/yarn
  npm:
    version: 10.9.2
    path: ~/.nvm/versions/node/v23.10.0/bin/npm
  Watchman:
    version: 2025.04.14.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.24978.46.2431.13208083
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.2
    wanted: 0.78.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
No Stacktrace, as no crash just incorrect values returned from API
MANDATORY Reproducer

https://snack.expo.dev/ci1UBlgM8PsixJnwYqW1d

Screenshots and Videos

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Dimensions API 的 iOS 实现开始,并将其窗口和屏幕计算与 Android 进行比较。在具有 Safe Areas 的设备上运行必需的 Snack 复现程序,然后验证 window.height 会排除 Safe Areas,而 screen.height 保持当前行为不变。

由索引模型根据 Issue 内容生成。

评估

技术栈
ios, react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。