Skip to content

Commit 99bb911

Browse files
committed
Reduce the number of calculation for label size
1 parent 4422020 commit 99bb911

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

Sources/Layout/MessageSizeCalculator.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,10 @@ open class MessageSizeCalculator: CellSizeCalculator {
186186
}
187187

188188
internal func labelSize(for attributedText: NSAttributedString, considering maxWidth: CGFloat) -> CGSize {
189-
let estimatedHeight = attributedText.height(considering: maxWidth)
190-
let estimatedWidth = attributedText.width(considering: estimatedHeight)
189+
let constraintBox = CGSize(width: maxWidth, height: .greatestFiniteMagnitude)
190+
let rect = attributedText.boundingRect(with: constraintBox, options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).integral
191191

192-
let finalHeight = ceil(estimatedHeight)
193-
let finalWidth = estimatedWidth > maxWidth ? maxWidth : ceil(estimatedWidth)
194-
195-
return CGSize(width: finalWidth, height: finalHeight)
192+
return rect.size
196193
}
197194
}
198195

0 commit comments

Comments
 (0)