Repository navigation
Conversation
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, so a 16 pt font in a 24 pt line is drawn 4 pt low. 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>
Visual regressionNo visual differences at android: no capture |
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, its placeholder and typed text 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 font in a 24 pt line is drawn 4 pt low. CSS splits the leading equally above and below the glyphs (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. With this change a single-line field draws without the line height. It is removed from:Multi-line fields keep the line height, which spaces their lines.
Layout measures the field from the attributed string stored in the state, so that string keeps its line heights and the field measures as before. Nested
<Text>runs can have line heights of their own, so a private attribute records the line height removed from each range of the field's text, and the text written back to the state after an edit gets each range's own value again. Text typed into an empty field, or set bysetTextAndSelection, has no record and gets the input's own line height. Both conversions are inRCTTextInputUtils.When the input's text attributes change, the field gets new default text attributes, and
UITextFieldapplies them to all of its text, which replaces every attribute of every range, records included. Nested runs then have the input's line height, as they do onmainafter the same change.When
multilinechanges, the default text attributes are computed again. The text needs no conversion:RCTCopyBackedTextInputgives the new backed view the plain string without attributes, and aUITextFieldapplies its default text attributes to all of its text.Line heights are omitted only when the input itself has a
lineHeight. A single-line input without one whose nested<Text>sets alineHeightdraws as onmain.A baseline offset is not an alternative: the field editor ignores it for the text being edited, so only the placeholder would move.
Changelog:
[IOS] [FIXED] - Center the text and placeholder of a single-line
TextInputvertically within itslineHeightTest Plan:
Ran:
Run on this base (2026-11-28, Xcode 27.1, iOS 27.0 simulator, iPhone 18 Pro):
RCTTextInputComponentView.mmfrommainand the rest kept:testSingleLineInputDrawsWithoutLineHeightfails (the minimum and maximum line height are 40, not 0). The other 7 pass.multilinecondition removed from the default text attributes update inupdateProps:oldProps::testInputThatBecomesMultilineDrawsWithLineHeightfails (0, not 40).Tests, in
React/Tests/Text:RCTTextInputUtilsTest,testRestoringLineHeightGivesEachRunItsOwn: a string with runs of line height 24 and 40 has none after omitting, and 24 and 40 again after restoring with a default of 24.RCTTextInputUtilsTest,testRestoringLineHeightGivesUnrecordedTextTheDefault: text without a record gets the default.RCTTextInputUtilsTest,testOmittingRecordsNothingForTextWithoutALineHeight: text whose line height is already omitted, assetTextAndSelectionbuilds it from the field's default attributes, gets no record and restores to the default.RCTTextInputComponentViewTests,testSingleLineInputDrawsWithoutLineHeight: a single-line input withlineHeight: 40has no minimum or maximum line height in the paragraph style of the backed field's default text attributes, and keeps 40 to write back to the state.RCTTextInputComponentViewTests,testMultilineInputDrawsWithLineHeight: a multi-line input keeps 40. It passes onmainand guards the multi-line branch.RCTTextInputComponentViewTests,testInputThatBecomesMultilineDrawsWithLineHeight: a single-line input that becomes multi-line has 40 again.The component view tests turn off font scaling in their props: unit tests run without an application, so
RCTFontSizeMultiplier()is 0 there and would scale every line height to 0.React/Testsbelongs to theReact-RCTFabricpod'sTeststest spec, which RNTester's Podfile does not install. To run it, I added:testspecs => ['Tests']to theReact-RCTFabricpod inscripts/cocoapods/fabric.rb, narrowed the test spec'ssource_filesto these two test files, and added an empty Swift file to the test spec so the bundle links the Swift runtime thatRCTSwiftUIneeds. None of that is part of this change. No test drives the component view's state: that the state receives the restored text, and that a change ofmultilinereports no edit, are covered only by reading the code. The tests build the view without a state or an event emitter.Checked in RNTester (Debug, same simulator) with a local example that is not part of this change: 16 pt single-line inputs with a value and with a placeholder at
lineHeight24 and 40,<TextInput style={{lineHeight: 24}}><Text style={{lineHeight: 40}}>Hi</Text></TextInput>, and a multi-line input atlineHeight40, each with a border and a guide line at its vertical center.main, the single-line text and placeholders sit at the bottom of their fields, and atlineHeight40 the text crosses the bottom border.<Text>, which is as tall as its 40 pt run. The multi-line input draws as onmain.Not checked: typed text, the nested input's height after a character is typed, and that switching
multilineon while the input has text does not fireonChange. I had no way to type into the simulator.🤖 Generated with Claude Code