Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ NSString *RCTNSStringFromStringApplyingTextTransform(NSString *string, facebook:

void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText);

void RCTApplyBaselineOffsetForRange(NSMutableAttributedString *attributedText, NSRange attributedTextRange);

/*
* Whether two `NSAttributedString` lead to the same underlying displayed text, even if they are not strictly equal.
* I.e. is one string substitutable for the other when backing a control (which may have some ignorable attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,18 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex

void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
{
[attributedText.string enumerateSubstringsInRange:NSMakeRange(0, attributedText.length)
options:NSStringEnumerationByLines | NSStringEnumerationSubstringNotRequired
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
RCTApplyBaselineOffsetForRange(attributedText, enclosingRange);
Copy link
Contributor Author

@tomekzaw tomekzaw May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should use substringRange or enclosingRange here. For the context, enclosingRange includes the newline character and substringRange doesn't. Both work fine and both fix the issue.

}];
}

void RCTApplyBaselineOffsetForRange(NSMutableAttributedString *attributedText, NSRange attributedTextRange)
__block CGFloat maximumLineHeight = 0;

[attributedText enumerateAttribute:NSParagraphStyleAttributeName
inRange:NSMakeRange(0, attributedText.length)
inRange:attributedTextRange
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
if (!paragraphStyle) {
Expand All @@ -314,7 +322,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
__block CGFloat maximumFontLineHeight = 0;

[attributedText enumerateAttribute:NSFontAttributeName
inRange:NSMakeRange(0, attributedText.length)
inRange:attributedTextRange
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(UIFont *font, NSRange range, __unused BOOL *stop) {
if (!font) {
Expand All @@ -332,7 +340,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)

[attributedText addAttribute:NSBaselineOffsetAttributeName
value:@(baseLineOffset)
range:NSMakeRange(0, attributedText.length)];
range:attributedTextRange];
}

static NSMutableAttributedString *RCTNSAttributedStringFragmentFromFragment(
Expand Down
Loading