react / react/react-native

aspectRatio ignores maxWidth constraint in dimension calculations

Offen
#57,304 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs: Triage :mag:
Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

Description

When a View has both aspectRatio and maxWidth style properties, the aspect ratio calculation ignores the maxWidth constraint.

While maxWidth is correctly applied to limit the view's final width, aspectRatio appears to compute dimensions based only on explicit or implicit width values, not on the effective constrained width.

Steps to reproduce
  1. Create a View with aspectRatio: 3 and either:
  • No explicit width (flex-based sizing), or
  • Explicit width (e.g., width: 300)
  • Add maxWidth: 200 (smaller than effective width) to the same View
  1. Observe the aspect ratio is distorted:
  • Width correctly capped at 200px
  • Height still calculated from original width (300px)
  • Resulting ratio ≠ 3

See repro for full example.

React Native Version

0.85.3

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.5.1
  CPU: (8) arm64 Apple M2
  Memory: 337.28 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.14.1
    path: /Users/.../.nvm/versions/node/v24.14.1/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.11.0
    path: /Users/.../.nvm/versions/node/v24.14.1/bin/npm
  Watchman:
    version: 2022.11.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/.../.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.5
      - iOS 26.5
      - macOS 26.5
      - tvOS 26.5
      - visionOS 26.5
      - watchOS 26.5
  Android SDK:
    API Levels:
      - "33"
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-29 | Google APIs ARM 64 v8a
      - android-37.0 | 16 KB Page Size Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14344949
  Xcode:
    version: 26.5/17F42
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.16
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/.../.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.85.3
    wanted: 0.85.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
-
MANDATORY Reproducer

https://snack.expo.dev/@andreamartinez/aspectratio-react-native-bug

Screenshots and Videos

Observe how aspectRatio always fails when applying a maxWidth, both on iOS and Android.

Image Image

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 Expo Snack-Reproducer und überprüfe die gemeldeten Fälle mit aspectRatio, maxWidth, auf flex basierender Größenbestimmung und expliziter Breite unter Android. Verfolge die für diese Einschränkungen verantwortliche Laufzeitberechnung des Layouts; abgeschlossen ist die Arbeit, wenn eine durch maxWidth begrenzte Breite eine Höhe ergibt, die das angeforderte Seitenverhältnis beibehält, und eine Regressionstestabdeckung für die Fälle des Reproducers vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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