mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 02:22:44 +02:00
Move size computations to PillAttachmentViewProvider
This commit is contained in:
@@ -19,6 +19,11 @@ import UIKit
|
||||
/// Provider for mention Pills attachment view.
|
||||
@available(iOS 15.0, *)
|
||||
@objc class PillAttachmentViewProvider: NSTextAttachmentViewProvider {
|
||||
private static let pillAttachmentViewParameters = PillAttachmentView.Parameters(font: UIFont.systemFont(ofSize: 15),
|
||||
verticalMargin: 2.0,
|
||||
horizontalMargin: 4.0,
|
||||
avatarSideLength: 16.0)
|
||||
|
||||
override func loadView() {
|
||||
super.loadView()
|
||||
|
||||
@@ -32,7 +37,27 @@ import UIKit
|
||||
return
|
||||
}
|
||||
|
||||
view = PillAttachmentView(withPillData: pillData)
|
||||
view = PillAttachmentView(frame: CGRect(origin: .zero, size: Self.size(forDisplayText: pillData.displayText)),
|
||||
parameters: Self.pillAttachmentViewParameters,
|
||||
andPillData: pillData)
|
||||
view?.alpha = pillData.alpha
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 15.0, *)
|
||||
extension PillAttachmentViewProvider {
|
||||
/// Computes size required to display a pill for given display text.
|
||||
///
|
||||
/// - Parameter displayText: display text for the pill
|
||||
/// - Returns: required size for pill
|
||||
static func size(forDisplayText displayText: String) -> CGSize {
|
||||
let label = UILabel(frame: .zero)
|
||||
label.text = displayText
|
||||
label.font = pillAttachmentViewParameters.font
|
||||
let labelSize = label.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude,
|
||||
height: pillAttachmentViewParameters.pillBackgroundHeight))
|
||||
|
||||
return CGSize(width: labelSize.width + pillAttachmentViewParameters.totalWidthWithoutLabel,
|
||||
height: pillAttachmentViewParameters.pillHeight)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user