mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 09:32:52 +02:00
Fix: truncate pills if they are too long
This commit is contained in:
@@ -72,6 +72,8 @@ struct PillTextAttachmentData: Codable {
|
||||
var alpha: CGFloat
|
||||
/// Font for the display name
|
||||
var font: UIFont
|
||||
/// Max width
|
||||
var maxWidth: CGFloat
|
||||
|
||||
/// Helper for preferred text to display.
|
||||
var displayText: String {
|
||||
@@ -93,12 +95,14 @@ struct PillTextAttachmentData: Codable {
|
||||
items: [PillTextAttachmentItem],
|
||||
isHighlighted: Bool,
|
||||
alpha: CGFloat,
|
||||
font: UIFont) {
|
||||
font: UIFont,
|
||||
maxWidth: CGFloat = CGFloat.greatestFiniteMagnitude) {
|
||||
self.pillType = pillType
|
||||
self.items = items
|
||||
self.isHighlighted = isHighlighted
|
||||
self.alpha = alpha
|
||||
self.font = font
|
||||
self.maxWidth = maxWidth
|
||||
}
|
||||
|
||||
// MARK: - Codable
|
||||
@@ -108,6 +112,7 @@ struct PillTextAttachmentData: Codable {
|
||||
case isHighlighted
|
||||
case alpha
|
||||
case font
|
||||
case maxWidth
|
||||
}
|
||||
|
||||
enum PillTextAttachmentDataError: Error {
|
||||
@@ -126,6 +131,7 @@ struct PillTextAttachmentData: Codable {
|
||||
} else {
|
||||
throw PillTextAttachmentDataError.noFontData
|
||||
}
|
||||
maxWidth = try container.decode(CGFloat.self, forKey: .maxWidth)
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
@@ -136,6 +142,7 @@ struct PillTextAttachmentData: Codable {
|
||||
try container.encode(alpha, forKey: .alpha)
|
||||
let fontData = try NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false)
|
||||
try container.encode(fontData, forKey: .font)
|
||||
try container.encode(maxWidth, forKey: .maxWidth)
|
||||
}
|
||||
|
||||
// MARK: - Pill representations
|
||||
|
||||
Reference in New Issue
Block a user