mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
fix for the timestamp state change creating clipping
less verbose comment less verbos
This commit is contained in:
@@ -74,7 +74,15 @@ struct MessageText: UIViewRepresentable {
|
|||||||
@Environment(\.openURL) private var openURLAction
|
@Environment(\.openURL) private var openURLAction
|
||||||
@Environment(\.timelineContext) private var viewModel
|
@Environment(\.timelineContext) private var viewModel
|
||||||
@Environment(\.layoutDirection) private var layoutDirection
|
@Environment(\.layoutDirection) private var layoutDirection
|
||||||
@State private var computedSizes = [Double: CGSize]()
|
|
||||||
|
/// Cache key for `sizeThatFits`. Keyed on the reserved trailing size as well as the proposed
|
||||||
|
/// width to account for any changes on the send info label that happen after the first rendering.
|
||||||
|
private struct SizeCacheKey: Hashable {
|
||||||
|
let width: Double
|
||||||
|
let reservedSize: CGSize
|
||||||
|
}
|
||||||
|
|
||||||
|
@State private var computedSizes = [SizeCacheKey: CGSize]()
|
||||||
|
|
||||||
@State var attributedString: AttributedString {
|
@State var attributedString: AttributedString {
|
||||||
didSet {
|
didSet {
|
||||||
@@ -204,14 +212,15 @@ struct MessageText: UIViewRepresentable {
|
|||||||
|
|
||||||
func sizeThatFits(_ proposal: ProposedViewSize, uiView: MessageTextView, context: Context) -> CGSize? {
|
func sizeThatFits(_ proposal: ProposedViewSize, uiView: MessageTextView, context: Context) -> CGSize? {
|
||||||
let proposalWidth = proposal.width ?? UIView.layoutFittingExpandedSize.width
|
let proposalWidth = proposal.width ?? UIView.layoutFittingExpandedSize.width
|
||||||
|
let key = SizeCacheKey(width: proposalWidth, reservedSize: trailingReservedSize)
|
||||||
|
|
||||||
if let size = computedSizes[proposalWidth] {
|
if let size = computedSizes[key] {
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = uiView.sizeThatFits(CGSize(width: proposalWidth, height: UIView.layoutFittingCompressedSize.height))
|
let size = uiView.sizeThatFits(CGSize(width: proposalWidth, height: UIView.layoutFittingCompressedSize.height))
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
computedSizes[proposalWidth] = size
|
computedSizes[key] = size
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user