IceCubesApp/Packages/Status/Sources/Status/Row/Subviews/StatusRowHeaderView.swift

116 lines
3.2 KiB
Swift
Raw Normal View History

import DesignSystem
2023-02-21 06:23:42 +00:00
import Env
import Models
2023-02-18 06:26:48 +00:00
import SwiftUI
struct StatusRowHeaderView: View {
2023-02-19 14:29:07 +00:00
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@EnvironmentObject private var theme: Theme
2023-02-18 06:26:48 +00:00
let status: AnyStatus
let viewModel: StatusRowViewModel
2023-02-18 06:26:48 +00:00
var body: some View {
HStack(alignment: .center) {
Button {
viewModel.navigateToAccountDetail(account: status.account)
} label: {
accountView(status: status)
}
.buttonStyle(.plain)
Spacer()
2023-02-19 14:29:07 +00:00
if !isInCaptureMode {
threadIcon
contextMenuButton
}
}
.accessibilityElement()
.accessibilityLabel(Text("\(status.account.displayName)"))
}
2023-02-18 06:26:48 +00:00
@ViewBuilder
private func accountView(status: AnyStatus) -> some View {
HStack(alignment: .center) {
if theme.avatarPosition == .top {
AvatarView(url: status.account.avatar, size: .status)
}
2023-02-19 18:51:37 +00:00
VStack(alignment: .leading, spacing: 2) {
HStack(alignment: .firstTextBaseline, spacing: 2) {
Group {
EmojiTextApp(.init(stringValue: status.account.safeDisplayName), emojis: status.account.emojis)
.font(.scaledSubheadline)
.emojiSize(Font.scaledSubheadlinePointSize)
.fontWeight(.semibold)
.lineLimit(1)
accountBadgeView
.font(.footnote)
}
.layoutPriority(1)
if theme.avatarPosition == .leading {
dateView
2023-02-19 18:57:17 +00:00
.font(.scaledFootnote)
.foregroundColor(.gray)
.lineLimit(1)
} else {
Text("@\(theme.displayFullUsername ? status.account.acct : status.account.username)")
.font(.scaledFootnote)
.foregroundColor(.gray)
.lineLimit(1)
}
}
if theme.avatarPosition == .top {
2023-02-19 18:57:17 +00:00
dateView
2023-02-21 06:23:42 +00:00
.font(.scaledFootnote)
.foregroundColor(.gray)
.lineLimit(1)
} else if theme.displayFullUsername, theme.avatarPosition == .leading {
Text("@\(status.account.acct)")
.font(.scaledFootnote)
.foregroundColor(.gray)
.lineLimit(1)
.offset(y: 1)
}
}
}
}
private var accountBadgeView: Text {
if viewModel.status.account.bot {
return Text(Image(systemName: "gearshape.fill")) + Text(" ")
} else if viewModel.status.account.locked {
return Text(Image(systemName: "lock.fill")) + Text(" ")
}
return Text("")
}
2023-02-21 06:23:42 +00:00
private var dateView: Text {
Text(status.createdAt.relativeFormatted) +
Text("") +
Text(Image(systemName: viewModel.status.visibility.iconName))
}
2023-02-18 06:26:48 +00:00
@ViewBuilder
private var threadIcon: some View {
if viewModel.isThread {
Image(systemName: "bubble.left.and.bubble.right")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 15)
.foregroundColor(.gray)
}
}
2023-02-18 06:26:48 +00:00
private var contextMenuButton: some View {
Menu {
StatusRowContextMenu(viewModel: viewModel)
} label: {
Image(systemName: "ellipsis")
.frame(width: 20, height: 20)
}
.menuStyle(.borderlessButton)
.foregroundColor(.gray)
.contentShape(Rectangle())
.accessibilityHidden(true)
}
}