react / react/react-native

Dimensions API does not handles orientation change

Open
#50,861 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API: Dimensions Issue: Author Provided Repro
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

Description

Dimensions API always return portrait mode values (height > width) even if app was started in landscape mode.
Try to rotate device and check console output - height > width always.

Steps to reproduce
  1. npx @react-native-community/cli@latest init rn791

  2. cd rn791

  3. yarn

  4. cd ios && pod install

  5. add next lines of code to App.tsx
    `useEffect(() => {
    const updateOrientation = () => {
    const {height, width} = Dimensions.get('window');
    const orientation = width > height ? 'landscape' : 'portrait';
    console.log('new orientation: ', orientation);
    };

    updateOrientation();
    const subscription = Dimensions.addEventListener(
    'change',
    updateOrientation,
    );

    return () => {
    subscription?.remove();
    };
    }, []);`

React Native Version

0.79.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.4.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 104.02 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.12.0
    path: ~/.nvm/versions/node/v22.12.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v22.12.0/bin/yarn
  npm:
    version: 10.9.0
    path: ~/.nvm/versions/node/v22.12.0/bin/npm
  Watchman:
    version: 2024.11.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.24978.46.2431.13208083
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.1
    wanted: 0.79.1
  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
MANDATORY Reproducer

https://github.com/roman-zaitsev/rn791-dimensions-api-bug-reproducer

Screenshots and Videos

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mandatory rn791-dimensions-api-bug-reproducer and the orientation logging in App.tsx; rotate the iOS device or simulator and confirm the Dimensions change event output. Trace the iOS Dimensions API handling that produces those values, and consider the issue complete when width and height reflect the current orientation after rotation and the behavior is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.