Repository navigation
Conversation
Visual regressionNo visual differences at android: no capture |
A single-line `TextInput` whose `lineHeight` is larger than its font draws its value, its placeholder and typed text at the bottom of the line instead of in the middle. `lineHeight` reaches the field as the paragraph style's minimum and maximum line height, and TextKit puts all of the extra leading above the glyphs: a 16 pt system font in a 24 pt line gets about 5 pt of extra leading, all of it above. CSS splits the leading equally above and below the glyphs (https://www.w3.org/TR/CSS2/visudet.html#leading). Layout already makes a single-line field as tall as its line, and `UITextField` centers the font's own line in its text rect. A single-line field therefore draws without the line height: it is removed from the default text attributes, which also style the placeholder and typed text, and from the attributed text the field is given. Multi-line fields keep the line height, which spaces their lines. Layout measures the field from the attributed string in the state, so that string keeps its line heights. A private attribute records the line height removed from each range of the field's text, and the text written back to the state gets each range's own value again. Text typed into an empty field has no record and gets the input's line height. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ide
force-pushed
the
@ide/ios-single-line-input-line-height
branch
from
November 29, 2026 12:02
9fee22b to
6d92a69
Compare
ide
marked this pull request as ready for review
November 29, 2026 13:49
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
A single-line
TextInputwhoselineHeightis larger than its font draws its value and placeholder at the bottom of the line instead of in the middle; with a large enoughlineHeightthe text crosses the field's bottom border.lineHeightreaches the field as the paragraph style's minimum and maximum line height, and TextKit puts all of the extra leading above the glyphs: a 16 pt system font in a 24 pt line gets about 5 pt of extra leading, all of it above. CSS splits the leading equally above and below (CSS 2, "Leading and half-leading").Layout already makes a single-line field as tall as its line, and
UITextFieldcenters the font's own line in its text rect. So when the input has alineHeight, a single-line field now draws without it: it is removed from the default text attributes (which also style the placeholder) and from the field's attributed text. This applies to anylineHeighton a single-line input, including one smaller than the font's line. Multi-line fields keep it. A baseline offset would not work: the field editor ignores it for the text being edited.The state's attributed string keeps its line heights, so measurement is unchanged. A private attribute records the line height removed from each range, so text written back to the state gets each nested
<Text>run's value again; text with no record gets the input's.Limitations:
lineHeightwhose nested<Text>sets one draws as before.UITextFieldapplies the new defaults to all of its text, records included, so nested runs get the input's line height, as onmain.Changelog:
[IOS] [FIXED] - Center the text and placeholder of a single-line
TextInputvertically within itslineHeightTest Plan:
Xcode 27.1, iOS 27.0 simulator (iPhone 18 Pro):
New tests in
React/Tests/Text:RCTTextInputUtilsTest(omitting and restoring per-run line heights) andRCTTextInputComponentViewTests(single-line drops the line height from the field but not the state; multi-line keeps it, which passes onmain; becoming multi-line restores it). Onmain,testSingleLineInputDrawsWithoutLineHeightfails (40, not 0); without themultilinecondition inupdateProps:oldProps:,testInputThatBecomesMultilineDrawsWithLineHeightfails (0, not 40). Font scaling is off in these tests: without an applicationRCTFontSizeMultiplier()is 0.RNTester does not install the
React-RCTFabricTestsspec. To run it locally (not in this change): add:testspecs => ['Tests']inscripts/cocoapods/fabric.rb, narrow the spec'ssource_filesto these files, and add an empty Swift file forRCTSwiftUI's Swift runtime.In RNTester, with a local example of single-line, nested-run and multi-line inputs at
lineHeight24 and 40: onmainsingle-line text sits at the bottom and crosses the border at 40; on this branch it is centered, frames are unchanged, and multi-line draws as before.Not checked: typed text, the nested input's height after typing, that switching
multilinewith text does not fireonChange, and that the state receives the restored text (the tests build the view without a state).