Skip to content

Commit 6e73e19

Browse files
committed
feat(badge): make badge modif respond to control size.
1 parent 85ef255 commit 6e73e19

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

‎Snapper/Features/AlbumHistory/AlbumHistoryCard.swift‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct AlbumHistoryCard: View {
66
var body: some View {
77
VStack(alignment: .leading, spacing: 0) {
88
AlbumCover(url: album.coverImageUrl)
9-
.roundedOutline(lineWidth: 1)
9+
.roundedOutline(lineWidth: LineWidth.sm)
1010

1111
HStack(alignment: .center) {
1212
AlbumHeader(title: album.title, artist: album.artist)
@@ -17,34 +17,35 @@ struct AlbumHistoryCard: View {
1717
Spacer()
1818

1919
Icon(systemName: "star.fill")
20-
.favoriteIconStyle(isFavorited: album.isFavorite)
20+
.favoriteIconStyle(isFavorite: album.isFavorite)
2121

2222
Text((album.selectedAt.shortRelative(to: .now)))
2323
.badgeStyle()
24+
.controlSize(.mini)
2425
}
2526
.frame(height: 40)
2627
}
2728
}
2829
}
2930

3031
struct FavoriteIconStyle: ViewModifier {
31-
let isFavorited: Bool
32+
let isFavorite: Bool
3233

3334
func body(content: Content) -> some View {
3435
content
3536
.foregroundStyle(.accent)
3637
.symbolEffect(
3738
.bounce.up,
3839
options: .speed(2),
39-
value: isFavorited,
40+
value: isFavorite,
4041
)
41-
.opacity(isFavorited ? 1 : 0)
42+
.opacity(isFavorite ? 1 : 0)
4243
}
4344
}
4445

4546
extension View {
46-
func favoriteIconStyle(isFavorited: Bool) -> some View {
47-
modifier(FavoriteIconStyle(isFavorited: isFavorited))
47+
func favoriteIconStyle(isFavorite: Bool) -> some View {
48+
modifier(FavoriteIconStyle(isFavorite: isFavorite))
4849
}
4950
}
5051

‎Snapper/Features/AlbumSearch/AlbumCandidateRow.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct AlbumCandidateRow: View {
3131
.badgeStyle()
3232
}
3333
}
34+
.controlSize(.mini)
3435
}
3536
}
3637
}

‎Snapper/Navigation/AlertDestination.swift‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ extension AlertDestination {
2626
title: LocalizedStringResource = "Notice",
2727
action: @escaping @MainActor () -> Void = {},
2828
) -> Self {
29-
.init(
29+
Self(
3030
title: title,
3131
message: message,
3232
primary: .init(title: "OK", action: action),
3333
)
3434
}
3535
}
36+
37+
#if DEBUG
38+
#Preview {
39+
@Previewable @State var alertItem: AlertDestination?
40+
41+
VStack {
42+
Button("Show OK Alert") {
43+
alertItem = .ok(
44+
"The album was added to your history.",
45+
title: "Album created",
46+
)
47+
}
48+
.buttonStyle(.borderedProminent)
49+
}
50+
.withAlertDestination($alertItem)
51+
}
52+
#endif

‎Snapper/Navigation/AlertDestinationModifier.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension View {
4040
@Previewable @State var alertItem: AlertDestination?
4141

4242
VStack(spacing: 24) {
43-
Button("Acknowledge") {
43+
Button("Notice") {
4444
alertItem = AlertDestination(
4545
title: "Album created",
4646
message: "The album was added to your history.",

‎Snapper/UI/Components/Badge.swift‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ import SwiftUI
33
struct BadgeStyleModifier: ViewModifier {
44
let isActive: Bool
55

6+
@Environment(\.controlSize) private var controlSize
7+
8+
private var textStyle: Font.TextStyle {
9+
switch controlSize {
10+
case .mini: .caption2
11+
case .small: .caption
12+
case .regular: .body
13+
case .large: .title3
14+
case .extraLarge: .title2
15+
@unknown default: .body
16+
}
17+
}
18+
619
func body(content: Content) -> some View {
720
content
821
.padding(Padding.md)
9-
.font(.sligoilMicroBold(.caption))
22+
.font(.sligoilMicroBold(textStyle))
1023
.foregroundStyle(
1124
isActive
1225
? .themePrimary
@@ -18,7 +31,7 @@ struct BadgeStyleModifier: ViewModifier {
1831
.fill(.tint)
1932
} else {
2033
RoundedRectangle(cornerRadius: Radius.md)
21-
.stroke(.themePrimaryInverted)
34+
.stroke(.themePrimaryInverted, lineWidth: LineWidth.sm)
2235
}
2336
}
2437
}
@@ -72,6 +85,7 @@ struct FilterBar: View {
7285
.toggleStyle(.badge)
7386
}
7487
}
88+
.padding(1)
7589
}
7690
}
7791
}
@@ -85,12 +99,15 @@ private struct TestBadge: View {
8599
VStack {
86100
Text("Badge")
87101
.badgeStyle()
102+
.controlSize(.small)
88103

89104
Toggle("Toggle", isOn: $isOn1)
90105
.toggleStyle(.badge)
106+
.controlSize(.regular)
91107

92108
Toggle("Tinted toggle", isOn: $isOn2)
93109
.toggleStyle(.badge)
110+
.controlSize(.large)
94111
.tint(.blue)
95112
}
96113
}
@@ -119,7 +136,7 @@ private struct CompleteView: View {
119136
}
120137

121138
private var filteredItems: [Item] {
122-
guard selectedFilter != .all else {
139+
if selectedFilter == .all {
123140
return items
124141
}
125142

@@ -145,11 +162,11 @@ private struct CompleteView: View {
145162
Divider()
146163
}
147164
}
148-
// .border(.red)
149165
}
150166
.padding(.horizontal)
151167
}
152168
}
169+
153170
#Preview("Filter Bar") {
154171
CompleteView()
155172
}

0 commit comments

Comments
 (0)