Repository navigation
Commit 35955d1
authored
Fix Android TextInput placeholder ignoring lineHeight
## Summary:
On Android, a `TextInput` with a `lineHeight` draws its placeholder a few pixels off its text.
`lineHeight` reaches the text as a `CustomLineHeightSpan`, but the hint is set as a plain string, so it keeps the font's own line height. The hint now gets the same span, rebuilt when the placeholder, `lineHeight` or font scale changes. A removed `lineHeight` comes back as `0`: the hint stays plain then, since a 0-high span would hide it.
Related: #39145
## Changelog:
[ANDROID] [FIXED] - TextInput placeholder takes the input's `lineHeight`
## Test Plan:
- New tests in `ReactTextInputPropertyTest`. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest` passes.
- RNTester Playground on a Pixel 8 Pro: placeholder (left), same text typed (right), `fontSize: 16`, `lineHeight: 40`, single-line then multiline. Also checked: removing `lineHeight` at runtime, and font scale 1.5.
| Before | After |
| --- | --- |
| <img src="https://raw.githubusercontent.com/Pduhard/react-native/pr-assets/placeholder-line-height-before.png" width="400" /> | <img src="https://raw.githubusercontent.com/Pduhard/react-native/pr-assets/placeholder-line-height-after.png" width="400" /> |
Written with help from Claude Code, tested on device by me.
Differential Revision: D130917481
Pull Request resolved: #598251 parent 5441168 commit 35955d1
2 files changed
Lines changed: 53 additions & 1 deletion
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/views/textinput
- test/java/com/facebook/react/views/textinput
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| 396 | + | |
395 | 397 | | |
396 | 398 | | |
397 | 399 | | |
| |||
669 | 671 | | |
670 | 672 | | |
671 | 673 | | |
672 | | - | |
| 674 | + | |
673 | 675 | | |
674 | 676 | | |
675 | 677 | | |
676 | 678 | | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
677 | 700 | | |
678 | 701 | | |
679 | 702 | | |
| |||
1176 | 1199 | | |
1177 | 1200 | | |
1178 | 1201 | | |
| 1202 | + | |
1179 | 1203 | | |
1180 | 1204 | | |
1181 | 1205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
209 | 237 | | |
210 | 238 | | |
211 | 239 | | |
| |||
0 commit comments