react / react/react-native

Dimensions API does not handles orientation change

Offen
#50,861 5 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

API: Dimensions Issue: Author Provided Repro
Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem obligatorischen rn791-dimensions-api-bug-reproducer und der Protokollierung der Orientierung in App.tsx; drehe das iOS-Gerät oder den Simulator und bestätige die Ausgabe des Dimensions-Änderungsereignisses. Verfolge die Verarbeitung der iOS Dimensions API, die diese Werte erzeugt, und betrachte das Issue als abgeschlossen, wenn width und height nach der Drehung die aktuelle Orientierung widerspiegeln und das Verhalten durch einen geeigneten Test abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
react-native
Bereich
mobile
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.