mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 11:47:51 +00:00
61fe2a8158
Extract the unread notification count capsule from the room list cell into its own view so it can be reused elsewhere. It caps the displayed value at 99+ and comes in a medium size (used by the room list) and a small size.
49 lines
1.5 KiB
Swift
49 lines
1.5 KiB
Swift
//
|
|
// Copyright 2026 Element Creations Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
/// A capsule showing an unread notification count, capped at 99+.
|
|
struct NotificationCountBadge: View {
|
|
enum Size {
|
|
case small
|
|
case medium
|
|
}
|
|
|
|
let count: Int
|
|
var size: Size = .medium
|
|
|
|
var body: some View {
|
|
Text(count > 99 ? "99+" : "\(count)")
|
|
.font(size == .small ? .compound.bodyXSSemibold : .compound.bodySMSemibold)
|
|
.foregroundStyle(.compound.textOnSolidPrimary)
|
|
.lineLimit(1)
|
|
.padding(.horizontal, size == .small ? 4 : 6)
|
|
.frame(minWidth: size == .small ? 16 : 20, minHeight: size == .small ? 16 : 20)
|
|
.background(.compound.iconAccentPrimary, in: .capsule)
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
struct NotificationCountBadge_Previews: PreviewProvider, TestablePreview {
|
|
static var previews: some View {
|
|
VStack(spacing: 8) {
|
|
ForEach([Size.small, .medium], id: \.self) { size in
|
|
HStack(spacing: 8) {
|
|
NotificationCountBadge(count: 1, size: size)
|
|
NotificationCountBadge(count: 42, size: size)
|
|
NotificationCountBadge(count: 100, size: size)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private typealias Size = NotificationCountBadge.Size
|
|
}
|