-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: truncate pills if they are too long #7455
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My only question is about encoding/decoding these pills - I'm not sure where/when we do it. Does it make sense to encode a computed maxWidth with them? Could it be decoded to be displayed in a different size window (e.g. If the user is now a different split size on iPad)? If so, maybe it would make sense to not encode it, and instead set it back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @pixlwave, I've updated the code to reflect your suggestions. |
||
} | ||
|
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Long pills are now truncated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to infer the type of the default here :)