mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
88 lines
3.2 KiB
Swift
88 lines
3.2 KiB
Swift
// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionUIKit
|
|
import SessionUtilitiesKit
|
|
|
|
public extension SessionProBadge.Size{
|
|
// stringlint:ignore_contents
|
|
var cacheKey: String {
|
|
switch self {
|
|
case .mini: return "SessionProBadge.Mini"
|
|
case .small: return "SessionProBadge.Small"
|
|
case .medium: return "SessionProBadge.Medium"
|
|
case .large: return "SessionProBadge.Large"
|
|
}
|
|
}
|
|
}
|
|
|
|
public extension SessionProBadge {
|
|
fileprivate static let accessibilityLabel: String = Constants.app_pro
|
|
|
|
static func trailingImage(
|
|
size: SessionProBadge.Size,
|
|
themeBackgroundColor: ThemeValue
|
|
) -> SessionCell.TextInfo.TrailingImage {
|
|
return (
|
|
.themedKey(size.cacheKey, themeBackgroundColor: themeBackgroundColor),
|
|
accessibilityLabel: SessionProBadge.accessibilityLabel,
|
|
{ SessionProBadge(size: size, themeBackgroundColor: themeBackgroundColor) }
|
|
)
|
|
}
|
|
}
|
|
|
|
public extension String {
|
|
enum SessionProBadgePosition {
|
|
case leading, trailing
|
|
}
|
|
|
|
func addProBadge(
|
|
at postion: SessionProBadgePosition,
|
|
font: UIFont,
|
|
textColor: ThemeValue = .textPrimary,
|
|
proBadgeSize: SessionProBadge.Size,
|
|
spacing: String = " ",
|
|
using dependencies: Dependencies
|
|
) -> ThemedAttributedString {
|
|
let base = ThemedAttributedString()
|
|
switch postion {
|
|
case .leading:
|
|
base.append(
|
|
ThemedAttributedString(
|
|
imageAttachmentGenerator: {
|
|
(
|
|
UIView.image(
|
|
for: .themedKey(proBadgeSize.cacheKey, themeBackgroundColor: .primary),
|
|
generator: { SessionProBadge(size: proBadgeSize) }
|
|
),
|
|
SessionProBadge.accessibilityLabel
|
|
)
|
|
},
|
|
referenceFont: font
|
|
)
|
|
)
|
|
base.append(ThemedAttributedString(string: spacing))
|
|
base.append(ThemedAttributedString(string: self, attributes: [.font: font, .themeForegroundColor: textColor]))
|
|
case .trailing:
|
|
base.append(ThemedAttributedString(string: self, attributes: [.font: font, .themeForegroundColor: textColor]))
|
|
base.append(ThemedAttributedString(string: spacing))
|
|
base.append(
|
|
ThemedAttributedString(
|
|
imageAttachmentGenerator: {
|
|
(
|
|
UIView.image(
|
|
for: .themedKey(proBadgeSize.cacheKey, themeBackgroundColor: .primary),
|
|
generator: { SessionProBadge(size: proBadgeSize) }
|
|
),
|
|
SessionProBadge.accessibilityLabel
|
|
)
|
|
},
|
|
referenceFont: font
|
|
)
|
|
)
|
|
}
|
|
|
|
return base
|
|
}
|
|
}
|