Skip to content

[iOS] Lay out multiline TextInput lines without the font's leading - #60086

Open
jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/ios-text-font-leading-descenders
Open

jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/ios-text-font-leading-descenders

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Refs #59842 (fixes its multiline part; see "Not addressed" for the rest).

React Native measures iOS text with NSLayoutManager.usesFontLeading = NO, a choice that dates back to #27195. A multiline TextInput is therefore sized for lines of ascender + descender. RCTUITextView kept UIKit's default and laid its lines out with the font's leading on top. Most fonts have no leading, but 62 of the 186 font families on macOS do, including every Hiragino family (8 pt at 16 pt, 0.5 em), Times New Roman, PT Sans, Geeza Pro and the Indic Sangam/Kohinoor families. For these fonts the text doesn't fit the view React Native measured:

This change turns the font's leading off in RCTUITextView as well, so the multiline input lays out its lines the way they were measured and the way <Text> draws them. On iOS 16+, UIKit backs the view with TextKit 2, so the property is set on its NSTextLayoutManager; that property exists on TextKit 2, so the view doesn't fall back to TextKit 1. Where UIKit uses TextKit 1, it is set on its NSLayoutManager. #45268 found the same missing setting in 2024; it was closed as a duplicate of #39145, which is a different bug (see below).

Changelog:

[IOS] [FIXED] - Multiline TextInput no longer adds the font's leading to its lines, so fonts with leading such as Hiragino Sans fit the measured height

Test Plan:

RNTester on an iOS 26.5 simulator (iPhone 17 Pro), New Architecture, Debug. The Playground rendered, once in Hiragino Sans and once in the system font: a single-line TextInput with a value, one with a placeholder, a two-line <Text>, a two-line multiline TextInput, a <Text> with lineHeight: 24, and a multiline TextInput with lineHeight: 24. I built the app with and without the change and relaunched it for each run.

Multiline TextInput, Hiragino Sans 16 pt Before After
no lineHeight (measured 37.33 pt) scrolls ("2 pages", 68%), first line cut off fits ("1 page"), laid out like <Text>
lineHeight: 24 (measured 53.33 pt) scrolls ("2 pages", 68%) fits ("1 page")
selection of one line ~24 pt tall as tall as the line
  • System font: the whole system-font section is pixel-identical before and after (PSNR = ∞ on full-resolution screenshots), since the system font has no leading.
  • node scripts/clang-format.js --check on the changed file passes.

Before / after, Hiragino Sans:

Hiragino Sans, before (left) and after (right)

Selection after the change:

Selection of one line after the change

Interaction with #39145 / #56487

With an explicit lineHeight, TextInput on iOS puts the glyphs at the bottom of each line instead of centering them as <Text> does. That is #39145, and #56487 addresses it. On main this already shows for the system font: compare <Text> (top) with a multiline TextInput (bottom), both with lineHeight: 24:

System font with lineHeight 24: Text (top) and multiline TextInput (bottom) on main

For Hiragino Sans, the 8 pt of leading used to hide that. After this change Hiragino behaves like the system font in this case, and since Hiragino's glyphs reach 1.46 pt below its declared descent, the last line's descenders touch the bottom edge until #56487 centers the line. This change and #56487 touch different lines of RCTUITextView.mm.

Not addressed

Items 1 and 2 of #59842, descenders clipped in <Text> and in single-line TextInput, come from the font's metrics. Hiragino Sans declares a descent of 1.92 pt at 16 pt, but g j p q y reach 3.38 pt below the baseline. With the no-leading layout from #27195, the glyphs' ink falls outside the line box. Changing that would change the height of <Text> for every font with leading, so it is out of scope here.

Not tested: a physical device, and the TextKit 1 branch (iOS 15, or a UITextView that UIKit has switched to TextKit 1).

React Native measures text with NSLayoutManager.usesFontLeading set to
NO (since react#27195), so a multiline TextInput is sized for lines of
ascender + descender. RCTUITextView kept UIKit's default and laid its
lines out with the font's leading on top. For a font with leading, the
text then didn't fit the measured view: with Hiragino Sans at 16 pt each
line took 24 pt instead of 16 pt, the view scrolled, its first line was
cut off and the selection highlight was a line and a half tall. An
explicit lineHeight didn't prevent it.

Turn the font's leading off in RCTUITextView too, on its
NSTextLayoutManager, or on its NSLayoutManager where UIKit uses TextKit
1. Fonts without leading, such as the system font, lay out as before.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 17, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 17, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at c24d41a60d78.

android: no capture

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant