mirror of
https://github.com/MessageKit/MessageKit.git
synced 2026-02-06 19:03:19 +00:00
Fixed boundingRect(with:options:) miscalculation of MessageLabel like text Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user