Skip to content

onTextLayout incorrectly returns multiple lines for text that renders in a single line #54552

Open

Description

@SMhdAsadi

Description

onTextLayout is returning incorrect lines data for simple single-line text.
In previous React Native versions (tested on Expo 52 with react-native 0.79), the lines array matched the actual number of rendered lines. After the latest update (RN 0.81), some texts that clearly render in one line are reported as two lines.

This breaks logic that depends on overflow detection (e.g., switching between normal text and marquee scrolling). Because onTextLayout now gives false positives, it’s impossible to reliably detect when text exceeds one line.

Steps to reproduce

The bug is present in Expo template when created with npx create-expo-app@latest.

  1. Install the dependencies npm install
  2. Open the app in Expo Go application
  3. See the log in terminal. You should see the text is rendered in one line, but onTextLayout gives an array with 2 items.

React Native Version

0.81.5

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 286.83 MB / 18.00 GB
  Shell:
    version: 3.2.57
    path: /bin/sh
Binaries:
  Node:
    version: 22.12.0
    path: /Users/smhd/.nvm/versions/node/v22.12.0/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.0
    path: /Users/smhd/.nvm/versions/node/v22.12.0/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.5
    wanted: 0.81.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

info React Native v0.82.1 is now available (your project is running on v0.81.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.82.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.81.5&to=0.82.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

No stacktrace available. Not related in this case.

MANDATORY Reproducer

https://github.com/SMhdAsadi/onTextLayout-issue-rn81

Screenshots and Videos

This is the first page of a new Expo project in default template:

Image

The title "Welcome!" is rendered in one line, but is reported to be in two lines in onTextLayout prop.

Activity

  1. IslamRustamov commented on Nov 16, 2025

    @IslamRustamov
    Contributor
    Image

    created clean app with npx create-expo-app@latest and didn't reproduce the issue, maybe you can show what was logged in console?

  2. SMhdAsadi commented on Nov 17, 2025

    @SMhdAsadi
    Author

    Sure. It produces two values in the array like this:

    "Welcome!" lines are: ["Welcome", "!"]
    

    Actually this is the entire e.nativeEvent.lines content:

    [{"ascender": 27.047618865966797, "capHeight": 23.00190544128418, "descender": 4.952381134033203, "height": 32, "text": "Welcome", "width": 132.84970092773438, "x": 0, "xHeight": 17.00190544128418, "y": 0}, {"ascender": 27.047618865966797, "capHeight": 23.00190544128418, "descender": 4.952381134033203, "height": 32, "text": "!", "width": 8.7619047164917, "x": 0, "xHeight": 17.00190544128418, "y": 32}]
    

    And for more info, this is the dimensions of emulator I use for testing:

    Image
  3. Thotaharshavardhani commented on Nov 24, 2025

    @Thotaharshavardhani

    Hello @SMhdAsadi , I was able to reproduce the issue. onTextLayout is returning two lines for text that visually renders in a single line on Expo/RN 0.81+. Thanks for reporting!

  4. gigobyte commented on Jan 22, 2026

    @gigobyte

    I was able to reproduce it with a much smaller example on RN 0.81.4:

    <View style={{ flexDirection: 'row' }}>
      <View style={{ flexGrow: 1 }} />
      <Text onTextLayout={(e) => Alert.alert(e.nativeEvent.lines.length.toString())}>
        POS
      </Text>
    </View>
    Image
  5. salmabs commented on Jan 27, 2026

    @salmabs

    +1

  6. dexical30 commented on Apr 4, 2026

    @dexical30

    I tracked this down and opened a PR with a proposed fix:

    The issue appears to come from using floor(width) when building the measurement StaticLayout for onTextLayout on Android. In some cases this makes the measurement layout 1px narrower than the rendered layout, which leads to incorrect line splitting being reported.

    Would appreciate any review or feedback.

  7. SimonWithoutGarfunkle commented on Apr 28, 2026

    @SimonWithoutGarfunkle

    +1
    same issue
    "hello" is displayed on two lines, but "hello test" and "Hello", which are longer, are correctly displayed on one line.

    LOG [chat][hello][textLayout] 287 {"linesCount": 2, "linesText": ["hell", "o"]}

    thank you for the fix @dexical30 hope it will be added soon !

  8. gigobyte commented on Oct 16, 2026

    @gigobyte

    For anyone wondering - this has been fixed in v0.86.0 - 90c2c59

    This issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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