react / react/react-native

Incorrect font scaling with adjustsFontSizeToFitWidth

Offen
#52,642 14 Kommentare 17 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Description

Sometimes <Text> element that has both lineHeight and adjustsFontSizeToFit sometimes shrinks the text even if there is enough place for it to be rendered.

It seems to happen when there is a fractional height separator in the layout.
There seem to be two problems:

  1. The font is scaled although there is enough space for the text to be rendered with the original font-size
  2. minimumFontScale seems not to be respected
Steps to reproduce

Here is minimal repro code of the app (also available in the expo snack)

When running the app the 2nd and 7th text element seem to be wrongly scaled (changing the number of element, the height of the separator or even fast-refresh seem to alter which elements are scaled incorrectly).

import { SafeAreaView, StyleSheet, Text, View } from "react-native";

const styles = StyleSheet.create({
  container: {
    alignItems: "center",
    justifyContent: "center",
  },
  text: {
    fontSize: 12,
    lineHeight: 20,
    width: 200,
  },
  separator: {
    height: 0.5,
    width: 200,
    backgroundColor: "green",
  },
});

const Test = () => (
  <Text
    style={styles.text}
    numberOfLines={1}
    adjustsFontSizeToFit
    minimumFontScale={0.8}
  >
    XXXXXXXXX
  </Text>
);

export default function App() {
  return (
    <SafeAreaView>
      <View style={styles.container}>
        <View style={styles.separator} />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
        <Test />
      </View>
    </SafeAreaView>
  );
}
React Native Version

0.79.5

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.5
  CPU: (14) arm64 Apple M4 Max
  Memory: 115.22 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.15.1
    path: ~/.nvm/versions/node/v20.15.1/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v20.15.1/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.15.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/alexander.vakrilov/.rvm/gems/ruby-3.3.6/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.3.6
    path: /Users/alexander.vakrilov/.rvm/rubies/ruby-3.3.6/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.5
    wanted: 0.79.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
No crash
MANDATORY Reproducer

https://snack.expo.dev/@vakrilov/0e4781

Screenshots and Videos
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

Führe zunächst den obligatorischen Expo Snack-Reproducer unter iOS aus und vergleiche die Textelemente mit dem Separator mit gebrochener Höhe sowie den Einstellungen für lineHeight, adjustsFontSizeToFit und minimumFontScale. Verfolge den nativen Textlayout-Pfad, sobald die fehlerhafte Skalierung reproduziert ist; abgeschlossen ist die Aufgabe, wenn der Text nicht verkleinert wird, solange ausreichend Platz vorhanden ist, und minimumFontScale eingehalten wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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