-
Notifications
You must be signed in to change notification settings - Fork 14
/
AssetTagsView.swift
96 lines (86 loc) · 1.88 KB
/
AssetTagsView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ComposableArchitecture
import SwiftUI
// MARK: - AssetTagsView
struct AssetTagsView: View {
let tags: [AssetTag]
var body: some View {
if !tags.isEmpty {
Group {
Text(L10n.AssetDetails.tags)
.textStyle(.body1Regular)
.foregroundColor(.app.gray2)
FlowLayout(spacing: .small2) {
ForEach(tags, id: \.self) { tag in
AssetTagView(tag: tag)
}
}
}
.transition(.opacity.combined(with: .scale(scale: 0.8)))
}
}
}
// MARK: - AssetTagView
struct AssetTagView: View {
let tag: AssetTag
var body: some View {
HStack(spacing: .small2) {
Image(asset: tag.icon)
Text(tag.name)
.textStyle(.body2HighImportance)
.foregroundColor(.app.gray2)
}
.padding(.vertical, .small3)
.padding(.horizontal, .small1)
.background {
Bullet()
.stroke(.app.gray4)
}
}
}
extension AssetTag {
public var name: String {
switch self {
case .officialRadix:
L10n.AssetDetails.Tags.officialRadix
case let .custom(string):
string.rawValue
}
}
public var icon: ImageAsset {
switch self {
case .officialRadix:
AssetResource.officialTagIcon
case .custom:
AssetResource.tagIcon
}
}
}
// MARK: - Bullet
struct Bullet: Shape {
typealias Path = SwiftUI.Path
func path(in rect: CGRect) -> Path {
Path { path in
let radius = 0.5 * rect.height
path.addRelativeArc(
center: .init(x: rect.maxX - radius, y: rect.midY),
radius: radius,
startAngle: .radians(-0.5 * .pi),
delta: .radians(.pi)
)
let corner: CGFloat = .small3
path.addRelativeArc(
center: .init(x: rect.minX + corner, y: rect.maxY - corner),
radius: corner,
startAngle: .radians(0.5 * .pi),
delta: .radians(0.5 * .pi)
)
path.addRelativeArc(
center: .init(x: rect.minX + corner, y: rect.minY + corner),
radius: corner,
startAngle: .radians(.pi),
delta: .radians(0.5 * .pi)
)
path.closeSubpath()
}
}
}