Files
session-ios/Session/Shared/Views/SessionProBadge+Utilities.swift
Ryan ZHAOandRyan ZHAO 907e1a9517 fix a couple of issues
2025-12-02 15:02:56 +11:00

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
}
}