Skip to content

Commit c24d41a

Browse files
committed
Lay out multiline TextInput lines without the font's leading on iOS
React Native measures text with NSLayoutManager.usesFontLeading set to NO (since #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.
1 parent bfea95f commit c24d41a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ - (instancetype)initWithFrame:(CGRect)frame
5858
self.textColor = [UIColor blackColor];
5959
// This line actually removes 5pt (default value) left and right padding in UITextView.
6060
self.textContainer.lineFragmentPadding = 0;
61+
// Lay out lines without the font's leading, as `RCTTextLayoutManager` measures them.
62+
if (@available(iOS 16.0, *)) {
63+
if (self.textLayoutManager != nil) {
64+
self.textLayoutManager.usesFontLeading = NO;
65+
} else {
66+
self.layoutManager.usesFontLeading = NO;
67+
}
68+
} else {
69+
self.layoutManager.usesFontLeading = NO;
70+
}
6171
#if !TARGET_OS_TV
6272
self.scrollsToTop = NO;
6373
#endif

0 commit comments

Comments
 (0)