IceCubesApp/Packages/Notifications/Sources/Notifications/NotificationRowView.swift

220 lines
7.9 KiB
Swift
Raw Normal View History

2022-12-19 11:28:55 +00:00
import DesignSystem
import EmojiText
2023-01-17 10:36:01 +00:00
import Env
import Models
2023-02-18 06:26:48 +00:00
import Network
2024-01-06 18:27:26 +00:00
import StatusKit
2023-01-17 10:36:01 +00:00
import SwiftUI
2022-12-19 11:28:55 +00:00
2023-09-18 19:03:52 +00:00
@MainActor
2022-12-19 11:28:55 +00:00
struct NotificationRowView: View {
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2022-12-19 11:28:55 +00:00
@Environment(\.redactionReasons) private var reasons
2023-01-17 10:36:01 +00:00
let notification: ConsolidatedNotification
let client: Client
let routerPath: RouterPath
let followRequests: [Account]
2023-01-17 10:36:01 +00:00
2022-12-19 11:28:55 +00:00
var body: some View {
HStack(alignment: .top, spacing: 8) {
if notification.accounts.count == 1 {
makeAvatarView(type: notification.type)
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityHidden(true)
} else {
makeNotificationIconView(type: notification.type)
.frame(width: AvatarView.FrameConfig.status.width,
height: AvatarView.FrameConfig.status.height)
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityHidden(true)
}
2024-01-22 08:05:22 +00:00
VStack(alignment: .leading, spacing: 0) {
makeMainLabel(type: notification.type)
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
// The main label is redundant for mentions
.accessibilityHidden(notification.type == .mention)
makeContent(type: notification.type)
if notification.type == .follow_request,
2023-02-18 06:26:48 +00:00
followRequests.map(\.id).contains(notification.accounts[0].id)
{
FollowRequestButtons(account: notification.accounts[0])
2022-12-19 11:28:55 +00:00
}
}
}
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityElement(children: .combine)
.accessibilityActions {
if notification.type == .follow {
accessibilityUserActions
}
}
2023-01-30 06:27:06 +00:00
.alignmentGuide(.listRowSeparatorLeading) { _ in
-100
}
2022-12-19 11:28:55 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-24 09:14:47 +00:00
private func makeAvatarView(type: Models.Notification.NotificationType) -> some View {
ZStack(alignment: .topLeading) {
AvatarView(notification.accounts[0].avatar)
makeNotificationIconView(type: type)
.offset(x: -8, y: -8)
2022-12-24 09:14:47 +00:00
}
.contentShape(Rectangle())
.onTapGesture {
routerPath.navigate(to: .accountDetailWithAccount(account: notification.accounts[0]))
}
}
private func makeNotificationIconView(type: Models.Notification.NotificationType) -> some View {
ZStack(alignment: .center) {
Circle()
.strokeBorder(Color.white, lineWidth: 1)
2023-02-25 18:54:46 +00:00
.background(Circle().foregroundColor(type.tintColor(isPrivate: notification.status?.visibility == .direct)))
.frame(width: 24, height: 24)
2023-02-28 17:48:22 +00:00
type.icon(isPrivate: notification.status?.visibility == .direct)
.resizable()
.scaledToFit()
.frame(width: 12, height: 12)
.foregroundColor(.white)
}
2022-12-24 09:14:47 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-24 09:14:47 +00:00
private func makeMainLabel(type: Models.Notification.NotificationType) -> some View {
VStack(alignment: .leading, spacing: 4) {
if notification.accounts.count > 1 {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 8) {
ForEach(notification.accounts) { account in
AvatarView(account.avatar)
.contentShape(Rectangle())
.onTapGesture {
routerPath.navigate(to: .accountDetailWithAccount(account: account))
}
}
}
.padding(.leading, 1)
.frame(height: AvatarView.FrameConfig.status.size.height + 2)
}.offset(y: -1)
}
2023-12-27 16:12:48 +00:00
if !reasons.contains(.placeholder) {
2023-12-27 15:07:16 +00:00
HStack(spacing: 0) {
EmojiTextApp(.init(stringValue: notification.accounts[0].safeDisplayName),
emojis: notification.accounts[0].emojis,
append: {
(notification.accounts.count > 1
? Text("notifications-others-count \(notification.accounts.count - 1)")
.font(.scaledSubheadline)
.fontWeight(.regular)
: Text(" ")) +
Text(type.label(count: notification.accounts.count))
.font(.scaledSubheadline)
.fontWeight(.regular) +
Text("")
.font(.scaledFootnote)
.fontWeight(.regular)
.foregroundStyle(.secondary) +
Text(notification.createdAt.relativeFormatted)
.font(.scaledFootnote)
.fontWeight(.regular)
.foregroundStyle(.secondary)
})
.font(.scaledSubheadline)
2024-02-05 07:55:24 +00:00
.emojiText.size(Font.scaledSubheadlineFont.emojiSize)
.emojiText.baselineOffset(Font.scaledSubheadlineFont.emojiBaselineOffset)
2023-12-27 15:07:16 +00:00
.fontWeight(.semibold)
.lineLimit(3)
.fixedSize(horizontal: false, vertical: true)
if let status = notification.status, notification.type == .mention {
Group {
Text("")
Text(Image(systemName: status.visibility.iconName))
}
.accessibilityHidden(true)
.font(.scaledFootnote)
.fontWeight(.regular)
.foregroundStyle(.secondary)
2023-01-21 14:16:52 +00:00
}
2023-12-27 15:07:16 +00:00
Spacer()
2023-01-21 14:16:52 +00:00
}
2023-12-27 15:07:16 +00:00
} else {
Text(" ")
.font(.scaledSubheadline)
.fontWeight(.semibold)
2022-12-24 09:14:47 +00:00
}
}
.contentShape(Rectangle())
.onTapGesture {
if notification.accounts.count == 1 {
routerPath.navigate(to: .accountDetailWithAccount(account: notification.accounts[0]))
} else {
routerPath.navigate(to: .accountsList(accounts: notification.accounts))
}
}
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityElement(children: .combine)
2022-12-24 09:14:47 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-24 09:14:47 +00:00
@ViewBuilder
private func makeContent(type: Models.Notification.NotificationType) -> some View {
if let status = notification.status {
2022-12-29 16:22:07 +00:00
HStack {
2023-01-17 06:54:59 +00:00
if type == .mention {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: true))
2024-02-14 11:48:14 +00:00
.environment(\.isMediaCompact, false)
2023-01-17 06:54:59 +00:00
} else {
StatusRowView(viewModel: .init(status: status,
client: client,
routerPath: routerPath,
showActions: false,
textDisabled: true))
2023-01-21 14:16:52 +00:00
.lineLimit(4)
.environment(\.isMediaCompact, true)
2023-01-17 06:54:59 +00:00
}
2022-12-29 16:22:07 +00:00
Spacer()
}
.environment(\.isCompact, true)
2022-12-24 09:14:47 +00:00
} else {
Group {
Text("@\(notification.accounts[0].acct)")
.font(.scaledCallout)
2023-12-04 14:49:44 +00:00
.foregroundStyle(.secondary)
2023-01-17 10:36:01 +00:00
if type == .follow {
EmojiTextApp(notification.accounts[0].note,
emojis: notification.accounts[0].emojis)
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityLabel(notification.accounts[0].note.asRawText)
.lineLimit(3)
.font(.scaledCallout)
2024-02-05 07:55:24 +00:00
.emojiText.size(Font.scaledCalloutFont.emojiSize)
.emojiText.baselineOffset(Font.scaledCalloutFont.emojiBaselineOffset)
2023-12-04 14:49:44 +00:00
.foregroundStyle(.secondary)
.environment(\.openURL, OpenURLAction { url in
routerPath.handle(url: url)
})
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
.accessibilityAddTraits(.isButton)
}
}
.contentShape(Rectangle())
.onTapGesture {
if notification.accounts.count == 1 {
routerPath.navigate(to: .accountDetailWithAccount(account: notification.accounts[0]))
} else {
routerPath.navigate(to: .accountsList(accounts: notification.accounts))
}
2022-12-24 09:14:47 +00:00
}
}
}
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
// MARK: - Accessibility actions
@ViewBuilder
private var accessibilityUserActions: some View {
ForEach(notification.accounts) { account in
Button("@\(account.username)") {
HapticManager.shared.fireHaptic(.notification(.success))
Accessibility tweaks + Notifications and Messages tab uplift (#1292) * Improve StatusRowView accessibility actions Previously, there was no way to interact with links and hashtags. Now, these are added to the Actions rotor * Hide `topPaddingView`s from accessibility * Fix accessible header rendering in non-filterable TimelineViews Previously, all navigation title views were assumed to be popup buttons. Now, we only change the representation for timelines that are filterable. * Combine tagHeaderView text elements Previously, these were two separate items * Prefer shorter Quote action label * Improve accessibility of StatusEmbeddedView Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions. * Add haptics to StatusRowView accessibility actions * Improve accessibility of ConversationsListRow This commit adds: - A combined representation of the component views - “Unread” as the first part of the label (if this is the case) - All relevant actions as custom actions - Reply as magic tap * Remove StatusRowView accessibilityActions if viewModel.showActions is false * Hide media attachments from accessibility if the view is not focused * Combine NotificationRowView accessibility elements; add user actions Previously, there was no real way to interact with these notifications. Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile. * Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning` This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well. --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 06:52:29 +00:00
routerPath.navigate(to: .accountDetail(id: account.id))
}
}
}
2022-12-19 11:28:55 +00:00
}