Commit 4e79973
committed
fix(ios): center typed text and caret in single-line TextInput when lineHeight > fontSize
UITextField's placeholder path (UILabel-based) honors
NSBaselineOffsetAttributeName, but the UIFieldEditor path that draws
typed text does not. So the Fabric baseline-offset fix centers
multi-line typed text (UITextView respects the offset) but leaves
single-line typed text pinned at the bottom of the
paragraphStyle-sized line box.
Override setDefaultTextAttributes: and setAttributedText: on
RCTUITextField to forward a stripped copy of the paragraph style to
super when paragraphStyle.maximumLineHeight > font.lineHeight —
minimumLineHeight and maximumLineHeight are zeroed out. UITextField
then renders the text at its natural font line height and its built-in
vertical centering positions it correctly in the bounds. Also drop
NSBaselineOffsetAttributeName on those ranges: the offset is wasted on
UITextField's typed-text draw path and a non-zero value inflates the
caret rect without moving the glyph.
The local _defaultTextAttributes ivar keeps the original paragraph
style so _placeholderTextAttributes and the caretRectForPosition:
override continue to see the real lineHeight.
For the caret itself: when lineHeight > font.lineHeight, UIKit sizes
the caret to the full line-box height, making it visually taller than
the surrounding glyph. Override caretRectForPosition: to match the
caret height to the font's intrinsic line height and center it within
the expanded line-box so it sits alongside the glyph.1 parent cba30b5 commit 4e79973
1 file changed
Lines changed: 75 additions & 3 deletions
Lines changed: 75 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | 94 | | |
96 | | - | |
| 95 | + | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
100 | 159 | | |
101 | 160 | | |
102 | 161 | | |
| |||
223 | 282 | | |
224 | 283 | | |
225 | 284 | | |
226 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
227 | 299 | | |
228 | 300 | | |
229 | 301 | | |
| |||
0 commit comments