react / react/react-native

useWindowDimensions() returns swapped height and width in iOS

未关闭
#29,290 45 条评论 8 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Description

When tested with iPad simulator, the useWindowDimensions(...) hook returns incorrect width and height.

React Native version:

Run react-native info in your terminal and copy the results here.

info Fetching system and libraries information...
System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
    Memory: 24.79 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.0 - /var/folders/k_/twn4fnrn6g56kn0xjlkp3zx00000gn/T/yarn--1594122179123-0.9086048405049534/node
    Yarn: 1.22.4 - /var/folders/k_/twn4fnrn6g56kn0xjlkp3zx00000gn/T/yarn--1594122179123-0.9086048405049534/yarn
    npm: 6.14.5 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 26, 28, 29
      Build Tools: 27.0.3, 28.0.3, 29.0.2, 30.0.0
      System Images: android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_242-release - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: ^0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found
✨  Done in 11.68s.

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Use react-native init to create a new project.
  2. Edit App.js with the following code
    import React from "react";
    import { Text, View, useWindowDimensions } from "react-native";
    
    export const App = () => {
      const { width, height } = useWindowDimensions();
    
      return (
        <View
          style={{
            width: "100%",
            height: "100%",
            alignItems: "center",
            justifyContent: "center",
          }}
        >
          <Text>{width > height ? "landscape" : "portrait"}</Text>
          <Text>{`width: ${width}, height: ${height}`}</Text>
        </View>
      );
    };
    

Expected Results

  1. At the first time I rotate the simulator to landscape, it should display "landscape" instead of nothing happens.
  2. At the second time the simulator rotates back to portrait position, it should render "portrait" on the screen.
  3. At the second time I rotate from portrait to landscape, it should display "landscape" instead of "portrait".

Snack, code example, screenshot, or link to a repository:

It is not easy to show device orientation features in snack, I'll attach screen recordings below.

Screen Recording 2020-07-07 at 7 39 07 PM

You may download the original video to pause for the rendered text.
Screen Recording 2020-07-07 at 7.39.07 PM.zip

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先使用 useWindowDimensions() 在 App.js 中进行复现,并在 iPad 模拟器上通过在竖屏和横屏之间旋转来验证行为。确认每次旋转后显示的方向以及宽度/高度值都能正确更新;该 issue 未指定要修改的 React Native 实现文件或测试。

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

评估

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

把新 issue 发到你的邮箱

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