Skip to content

Commit

Permalink
Support old and Fabric arch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Oct 17, 2023
1 parent 4817a95 commit aadbf6f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/react-native/Libraries/Text/Text/RCTTextShadowView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ - (NSTextStorage *)textStorageAndLayoutManagerThatFitsSize:(CGSize)size exclusiv
maximumFontSize:self.textAttributes.effectiveFont.pointSize];
}

[layoutManager ensureLayoutForTextContainer:textContainer];
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];

[textStorage enumerateAttribute:NSBackgroundColorAttributeName
inRange:characterRange
options:0
usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) {
NSRange truncatedRange =
[layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:range.location];

// Remove background color if glyphs is truncated
if (truncatedRange.location != NSNotFound && range.location >= truncatedRange.location) {
[textStorage removeAttribute:NSBackgroundColorAttributeName range:range];
}
}];

if (!exclusiveOwnership) {
[_cachedTextStorages setObject:textStorage forKey:key];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ TextMeasurement ParagraphLayoutManager::measure(

return cachedTextMeasurement_;
} else {
hostTextStorage_ = textLayoutManager_->getHostTextStorage(
attributedString, paragraphAttributes, layoutConstraints);
return textLayoutManager_->measure(
AttributedStringBox(attributedString),
paragraphAttributes,
layoutContext,
layoutConstraints,
nullptr);
hostTextStorage_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage
attachments.push_back(TextMeasurement::Attachment{rect, false});
}];

NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];

[textStorage enumerateAttribute:NSBackgroundColorAttributeName
inRange:characterRange
options:0
usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) {
NSRange truncatedRange =
[layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:range.location];

// Remove background color if glyphs is truncated
if (truncatedRange.location != NSNotFound && range.location >= truncatedRange.location) {
[textStorage removeAttribute:NSBackgroundColorAttributeName range:range];
}
}];

return TextMeasurement{{size.width, size.height}, attachments};
}

Expand Down

0 comments on commit aadbf6f

Please sign in to comment.