Skip to content

Commit acf0eb1

Browse files
fix(ios): re-seed paragraphStyle on typed TextInput text so baseline offset applies
The prior Fabric fix calls RCTApplyBaselineOffset on the incoming attributedString in _setAttributedString, but 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 in TextInputState. Without a paragraph style on the incoming string, RCTApplyBaselineOffsetForRange reads maximumLineHeight == 0 and returns early, so NSBaselineOffsetAttributeName never lands on typed text and glyphs end up pinned to the bottom of the paragraphStyle-sized line box. 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 baseline offset is computed and applied.
1 parent 4c1c231 commit acf0eb1

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,26 @@ - (void)_restoreTextSelectionAndIgnoreCaretChange:(BOOL)ignore
768768

769769
- (void)_setAttributedString:(NSMutableAttributedString *)attributedString
770770
{
771+
// When the user types, UIKit's typingAttributes drop NSParagraphStyleAttributeName, so the
772+
// attributedText round-tripping back through state lacks the paragraph style that
773+
// RCTApplyBaselineOffset needs. Re-seed paragraph style from defaultTextAttributes on ranges
774+
// that are missing it or carry a zero-lineHeight stub, so the helper can compute the offset.
775+
NSParagraphStyle *defaultParagraphStyle =
776+
_backedTextInputView.defaultTextAttributes[NSParagraphStyleAttributeName];
777+
if (defaultParagraphStyle && attributedString.length > 0) {
778+
[attributedString
779+
enumerateAttribute:NSParagraphStyleAttributeName
780+
inRange:NSMakeRange(0, attributedString.length)
781+
options:0
782+
usingBlock:^(NSParagraphStyle *style, NSRange range, __unused BOOL *stop) {
783+
if (!style || style.maximumLineHeight == 0) {
784+
[attributedString addAttribute:NSParagraphStyleAttributeName
785+
value:defaultParagraphStyle
786+
range:range];
787+
}
788+
}];
789+
}
790+
771791
RCTApplyBaselineOffset(attributedString);
772792

773793
if ([self _textOf:attributedString equals:_backedTextInputView.attributedText]) {

0 commit comments

Comments
 (0)