Skip to content

[Android] fontSize styles on nested Text elements aren't always applied #33418

@artemiswkearney

Description

@artemiswkearney

Description

On Android devices, large Text components will sometimes fail to apply the fontSize property of nested Text component's styles, resulting in text rendering with the parent's font size.
image
These lines of text all have the same style, but render at different sizes.

(Haven't tested whether this applies to things besides fontSize. When scrolling through the text, the bug seems periodic, happening to the last few Texts out of every group of some larger number.)

Version

0.67.3 (originally observed on 0.64.1)

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 2.65 GB / 15.76 GB
  Binaries:
    Node: 17.7.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.5.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.10.31402.337 (Visual Studio Community 2019), 15.9.28307.1033 (Visual Studio Community 2017)
  Languages:
    Java: 1.8.0_282 - C:\Program Files\OpenJDK\openjdk-8u282-b08\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.67.3 => 0.67.3
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Render a large number of Text components, each with their own style props including fontSize values, inside a Text component with a different fontSize
  2. Deploy your app to an Android device
  3. Observe that some of the text is rendered with the wrong font size

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/IbMg-oQqi
Measures the height of various Texts using onLayout events, then computes how far off the height of a large nested Text is from its expected height. Constants at the top of the file:

  • USE_DIFFERENT_HEIGHTS: If true, the newlines in between phrases will be rendered at a smaller font size. Seems to make the bug happen at lower phrase counts, but isn't required.
  • NUM_PHRASES: The number of phrases to render. On my test phone and on the Snack Android device, 52 seems to be the minimum number to reproduce with USE_DIFFERENT_HEIGHTS off, 37 with it on. Use higher values like 200 to see the periodic effect mentioned earlier.
  • THROW_IF_WRONG_HEIGHT: If true, throws an error if the height is too far from the expected value. Otherwise, just console.logs about it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions