useWindowDimensions() returns swapped height and width in iOS
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
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.
- Use
react-native initto create a new project. - Edit
App.jswith the following codeimport 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
- At the first time I rotate the simulator to landscape, it should display
"landscape"instead of nothing happens. - At the second time the simulator rotates back to portrait position, it should render
"portrait"on the screen. - 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.

You may download the original video to pause for the rendered text.
Screen Recording 2020-07-07 at 7.39.07 PM.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the App.js reproduction using useWindowDimensions() and verify the behavior on the iPad simulator while rotating between portrait and landscape. Confirm that the displayed orientation and width/height values update correctly after each rotation; the issue does not name the React Native implementation file or test to modify.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100