-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathLikeUserRowView.swift
More file actions
65 lines (57 loc) · 2.45 KB
/
Copy pathLikeUserRowView.swift
File metadata and controls
65 lines (57 loc) · 2.45 KB
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
import SwiftUI
import WordPressData
import WordPressUI
/// SwiftUI port of `LikeUserTableViewCell`: a 46pt circular avatar, the display name,
/// the `@username`, and a hairline bottom divider. Used in both the compact (single
/// column) and regular (multi-column) layouts of ``LikesListView``.
struct LikeUserRowView: View {
let user: LikeUser
/// Whether to draw the hairline bottom divider. The multi-column grid layout hides it
/// so cells don't carry stray separators; the single-column layout keeps it to match
/// the table it replaces.
var showsDivider = true
var body: some View {
VStack(spacing: 0) {
HStack(spacing: Metrics.avatarSpacing) {
// The avatar sizes itself (it scales with Dynamic Type via an internal
// @ScaledMetric), so it must not be pinned to a fixed frame here or it
// would overflow and overlap the text at large accessibility sizes.
AvatarView(
style: .single(URL(string: user.avatarUrl)),
diameter: Metrics.avatarDiameter,
placeholderImage: Image("gravatar").resizable()
)
.accessibilityHidden(true)
VStack(alignment: .leading, spacing: Metrics.labelSpacing) {
Text(user.displayName)
.font(.body)
.foregroundStyle(.primary)
Text(String(format: Strings.usernameFormat, user.username))
.font(.subheadline)
.foregroundStyle(.secondary)
}
Spacer(minLength: 0)
}
.padding(.horizontal, Metrics.horizontalPadding)
.padding(.vertical, Metrics.verticalPadding)
if showsDivider {
Divider()
.padding(.leading, Metrics.horizontalPadding)
}
}
}
private enum Metrics {
static let avatarDiameter: CGFloat = 46
static let avatarSpacing: CGFloat = 12
static let labelSpacing: CGFloat = 2
static let horizontalPadding: CGFloat = 20
static let verticalPadding: CGFloat = 12
}
private enum Strings {
static let usernameFormat = NSLocalizedString(
"@%1$@",
comment:
"Label displaying the user's username preceded by an '@' symbol. %1$@ is a placeholder for the username."
)
}
}