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
import SwiftUI
struct PostAuthorHeader: View {
@AppStorage("appFont") private var appFont = AppFont.system.rawValue
@AppStorage("hideAvatars") private var hideAvatars = false
@AppStorage("handlesOnly") private var handlesOnly = false
private var displayPreferences: DisplayPreferences {
DisplayPreferences(hideAvatars: hideAvatars, handlesOnly: handlesOnly)
}
@ScaledMetric(relativeTo: .body) private var handleFontSize: CGFloat = 18
let author: Post.Author
let postID: String
var date: Date?
var threadPosition: ThreadPosition?
var allowsAvatarImage = true
var accessibilityID = ""
let openProfile: () -> Void
var body: some View {
HStack(alignment: .center, spacing: 8) {
Button(action: openProfile) {
HStack(alignment: .center, spacing: 10) {
AuthorAvatar(
author: author, size: 44, allowsImage: allowsAvatarImage, ringWidth: ImageBorderStyle.width)
VStack(alignment: .leading, spacing: 2) {
Text(displayPreferences.name(author))
.font(
handlesOnly
? (AppFont(rawValue: appFont) ?? .system).fixedFont(size: handleFontSize)
: (AppFont(rawValue: appFont) ?? .system).font(.body)
)
.fontWeight(.semibold)
.foregroundStyle(.primary)
.lineLimit(1)
.truncationMode(.tail)
if !displayPreferences.handlesOnly {
Text("@\(author.handle)")
.appFont(.subheadline)
.foregroundStyle(.secondary)
.lineLimit(1)
.truncationMode(.tail)
}
}
}
.frame(minHeight: 44)
.padding(.vertical, handlesOnly ? 6 : 0)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityIdentifier(accessibilityID)
.layoutPriority(1)
Spacer(minLength: 0)
if let threadPosition {
Text("\(threadPosition.index.formatted())/\(threadPosition.count.formatted())")
.appFont(.caption, weight: .semibold)
.monospacedDigit()
.foregroundStyle(AppPalette.accent)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(AppPalette.accent.opacity(0.12), in: Capsule())
.fixedSize()
.accessibilityLabel("Thread post \(threadPosition.index) of \(threadPosition.count)")
.accessibilityIdentifier("threadPosition-\(postID)")
}
if let date {
PostTimestamp(date: date)
.fixedSize()
.accessibilityIdentifier("postTimestamp-\(postID)")
}
}
}
}
#if DEBUG
#Preview("Post author") {
VStack(spacing: 20) {
PostAuthorHeader(
author: PreviewContent.author, postID: "post-1", date: PreviewContent.date, openProfile: {})
PostAuthorHeader(author: PreviewContent.author, postID: "post-2", allowsAvatarImage: false, openProfile: {})
}
.padding()
}
#endif