diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cd7961a..1195ab39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ## Upcoming release +### Fixed + +- Fixed `boundingRect(with:options:)` miscalculation of `MessageLabel` , like text `Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩`、`Tomorrow is the day`. +[#824](https://github.com/MessageKit/MessageKit/pull/824) by [@zhongwuzw](https://github.com/zhongwuzw). + ### Changed - The `MessageData.emoji` case once again uses a default font of 2x the `messageLabelFont` size. diff --git a/Sources/Layout/MessageSizeCalculator.swift b/Sources/Layout/MessageSizeCalculator.swift index 7e563629..ef7a5ae3 100644 --- a/Sources/Layout/MessageSizeCalculator.swift +++ b/Sources/Layout/MessageSizeCalculator.swift @@ -24,6 +24,8 @@ import Foundation +private let additionalWidthForBoundingRectCalculation: CGFloat = 5.0 + open class MessageSizeCalculator: CellSizeCalculator { public init(layout: MessagesCollectionViewFlowLayout? = nil) { @@ -216,8 +218,9 @@ open class MessageSizeCalculator: CellSizeCalculator { internal func labelSize(for attributedText: NSAttributedString, considering maxWidth: CGFloat) -> CGSize { let constraintBox = CGSize(width: maxWidth, height: .greatestFiniteMagnitude) let rect = attributedText.boundingRect(with: constraintBox, options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).integral - - return rect.size + + // `boundingRect` method maybe not calculate correctly, like `Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩`, so we add 5 points to fix them temporary. + return CGSize(width: rect.width + additionalWidthForBoundingRectCalculation, height: rect.height) } }