Only create NSAttributedString if NSTextStorage is nil (#36773)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36773

Changelog: [internal]

Do not construct `NSAttributedString` if `NSTextStorage` exists. Creating `NSAttributedString` is expensive and it isn't needed to measure text if `NSTextStorage` `exists`

Reviewed By: cipolleschi

Differential Revision: D44620292

fbshipit-source-id: 0827c514e40fcbd9626d2b7d7b6d28a3332d9aa1
This commit is contained in:
Samuel Susla
2023-04-03 05:19:28 -07:00
committed by Facebook GitHub Bot
parent 9952dc2cc3
commit a675dd7faf
@@ -64,10 +64,14 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi
layoutConstraints:(LayoutConstraints)layoutConstraints
textStorage:(NSTextStorage *_Nullable)textStorage
{
return [self measureNSAttributedString:[self _nsAttributedStringFromAttributedString:attributedString]
paragraphAttributes:paragraphAttributes
layoutConstraints:layoutConstraints
textStorage:textStorage];
if (textStorage) {
return [self _measureTextStorage:textStorage];
} else {
return [self measureNSAttributedString:[self _nsAttributedStringFromAttributedString:attributedString]
paragraphAttributes:paragraphAttributes
layoutConstraints:layoutConstraints
textStorage:nil];
}
}
- (void)drawAttributedString:(AttributedString)attributedString