Commit 609af21
committed
fix(ios): center TextInput typed text when lineHeight > fontSize on Fabric
On Fabric, typed text in a TextInput renders too low when
lineHeight > fontSize — glyphs anchor to the bottom of the
attributed-string line box. Paper's facebook#38359 addressed this via
NSBaselineOffsetAttributeName, but the equivalent helper
RCTApplyBaselineOffset (already used by <Text> in RCTTextLayoutManager)
was never wired into the <TextInput> path.
Call RCTApplyBaselineOffset inside
RCTTextInputComponentView._setAttributedString: to add the baseline
offset before assigning the attributedString to the backed view. Widen
RCTNSAttributedStringFromAttributedString[Box] to return
NSMutableAttributedString * so the typed-text path avoids an extra
mutableCopy; the Value-mode path already built a mutable and returned
it typed as immutable, and OpaquePointer-mode now mutableCopy's
explicitly.
The helper alone is not enough: on each keystroke the attributedText
that round-trips UIKit → Fabric state → back drops
NSParagraphStyleAttributeName (UIKit's typingAttributes does not carry
the paragraph style, and _updateState stores the stripped attributedText
verbatim as an OpaquePointer). Without a paragraph style on the incoming
string, RCTApplyBaselineOffsetForRange reads maximumLineHeight == 0 and
returns early, so the offset is never applied to typed text.
Re-seed the paragraph style from defaultTextAttributes on any range
that lacks it (or carries a zero-lineHeight stub) before calling the
helper, so the offset is computed and applied for typed content too.
UITextView (multi-line) honors NSBaselineOffsetAttributeName for
rendered text; UITextField (single-line) does not — that path is
addressed in a separate commit.1 parent 9b8589a commit 609af21
3 files changed
Lines changed: 30 additions & 8 deletions
File tree
- packages/react-native
- ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager
- React/Fabric/Mounting/ComponentViews/TextInput
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
579 | | - | |
| 578 | + | |
| 579 | + | |
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
| |||
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
769 | | - | |
| 769 | + | |
770 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
771 | 793 | | |
772 | 794 | | |
773 | 795 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
| 408 | + | |
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | | - | |
| 431 | + | |
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
| 437 | + | |
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| |||
0 commit comments