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

345 lines
12 KiB
Swift
Raw Normal View History

2023-01-17 10:36:01 +00:00
import DesignSystem
2022-12-22 09:53:36 +00:00
import Env
2023-01-17 10:36:01 +00:00
import Models
2023-01-22 05:38:30 +00:00
import Nuke
2022-12-25 06:43:02 +00:00
import NukeUI
2023-01-17 10:36:01 +00:00
import SwiftUI
2023-10-16 17:08:59 +00:00
import MediaUI
2022-12-17 12:37:46 +00:00
2023-09-19 07:18:20 +00:00
@MainActor
public struct StatusRowMediaPreviewView: View {
2023-10-23 17:12:25 +00:00
@Environment(\.openWindow) private var openWindow
2023-02-19 14:29:07 +00:00
@Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool
@Environment(\.extraLeadingInset) private var extraLeadingInset: CGFloat
2023-02-19 14:29:07 +00:00
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
2023-03-03 11:41:38 +00:00
@Environment(\.isCompact) private var isCompact: Bool
2023-01-22 05:38:30 +00:00
@Environment(SceneDelegate.self) private var sceneDelegate
2023-09-19 07:18:20 +00:00
@Environment(UserPreferences.self) private var preferences
@Environment(QuickLook.self) private var quickLook
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2023-01-17 10:36:01 +00:00
public let attachments: [MediaAttachment]
public let sensitive: Bool
2022-12-24 07:29:45 +00:00
2022-12-22 09:53:36 +00:00
@State private var isQuickLookLoading: Bool = false
2023-01-03 07:45:27 +00:00
@State private var altTextDisplayed: String?
@State private var isAltAlertDisplayed: Bool = false
@State private var isHidingMedia: Bool = false
2023-01-17 10:36:01 +00:00
var availableWidth: CGFloat {
if UIDevice.current.userInterfaceIdiom == .phone &&
2023-02-22 18:09:39 +00:00
(UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) || theme.statusDisplayStyle == .medium
{
return sceneDelegate.windowWidth * 0.80
}
return sceneDelegate.windowWidth
}
var appLayoutWidth: CGFloat {
let avatarColumnWidth = theme.avatarPosition == .leading ? AvatarView.Size.status.size.width + .statusColumnsSpacing : 0
var sidebarWidth: CGFloat = 0
var secondaryColumnWidth: CGFloat = 0
2023-02-21 17:46:28 +00:00
let layoutPading: CGFloat = .layoutPadding * 2
2023-02-22 18:09:39 +00:00
if UIDevice.current.userInterfaceIdiom == .pad {
sidebarWidth = .sidebarWidth
if preferences.showiPadSecondaryColumn {
secondaryColumnWidth = .secondaryColumnWidth
}
}
return layoutPading + avatarColumnWidth + sidebarWidth + extraLeadingInset + secondaryColumnWidth
}
private var imageMaxHeight: CGFloat {
2023-03-03 11:41:38 +00:00
if isCompact {
2022-12-29 16:22:07 +00:00
return 50
}
2023-01-07 16:44:25 +00:00
if theme.statusDisplayStyle == .compact {
2023-02-22 06:26:32 +00:00
if attachments.count == 1 {
return 200
}
2023-01-07 16:44:25 +00:00
return 100
}
if attachments.count == 1 {
return 300
}
2023-01-19 06:45:42 +00:00
return attachments.count > 2 ? 150 : 200
}
2023-01-17 10:36:01 +00:00
private func size(for media: MediaAttachment) -> CGSize? {
2023-01-05 12:27:04 +00:00
if let width = media.meta?.original?.width,
2023-01-17 10:36:01 +00:00
let height = media.meta?.original?.height
{
return .init(width: CGFloat(width), height: CGFloat(height))
}
return nil
}
2023-01-17 10:36:01 +00:00
private func imageSize(from: CGSize, newWidth: CGFloat) -> CGSize {
2023-03-03 11:41:38 +00:00
if isCompact || theme.statusDisplayStyle == .compact || isSecondaryColumn {
return .init(width: imageMaxHeight, height: imageMaxHeight)
2022-12-29 16:22:07 +00:00
}
let ratio = newWidth / from.width
let newHeight = from.height * ratio
return .init(width: newWidth, height: newHeight)
}
2023-01-17 10:36:01 +00:00
2022-12-17 12:37:46 +00:00
public var body: some View {
Group {
if attachments.count == 1, let attachment = attachments.first {
makeFeaturedImagePreview(attachment: attachment)
.onTapGesture {
2023-10-23 17:12:25 +00:00
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestination.mediaViewer(attachments: attachments,
selectedAttachment: attachment))
} else {
quickLook.prepareFor(selectedMediaAttachment: attachment, mediaAttachments: attachments)
}
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(Self.accessibilityLabel(for: attachment))
Profile tab accessibility uplift (#1274) * Combine `joinedAtView` into one accessibility element Previously, the calendar image was visible with a nonsensical label. We use the `.combine` operator here to maintain the proper string formatting of the date. * Improve the accessibility of the AccountDetailHeaderView Previously, this image had no description and no indication that it had an associated interaction. Now, we wrap it in a button that performs the tap gesture action, and remove the element altogether if there is no avatar image set. This commit also handles the checkmark for supporter users * Tweak accessibility of Profile CustomInfoLabels This commit: - Reverses the order of title and value - Sets the value as an `accessibilityValue` - Adds a hint indicating what the button does, as they perform slightly different actions * Make Profile tab header image into a Button This element has an action associated with it (quicklook), so it makes more sense to have it as a button, and hide it if the user does not have an image set. Without the action it would have been considered decorative and should be hidden. * Change accessibilityLabel of Profile tab nav bar item to ‘Options’ “More” is considered overly generic. This commit also adds two additional user input label options * Add accessibility labels for the Profile tab `Picker` Previously, these labels were the default accessibility label provided by the SF symbol, that almost, but not quite, made sense * Remove StatusRowView swipe actions if VoiceOver is running These swipe actions are automagically added to the accessibility element’s custom actions, in addition to the ones already there, which means that there is a significant (and confusing) amount of doubling up going on. * Fix typo in StatusRowView.accessibilityActions * Add accessibilityLabels to all StatusRowActionsView actions * Provide explicit combined accessibility label for unfocused StatusRowView Previously, this was a synthesized label, which read the elements in their traversal order, and didn’t provide any context for which of the three numbers corresponded to replies, boosts or favourites. Now, we create an explicit combined label when the post isn’t being viewed by itself. * Improve accessibility of StatusRow(Reblog|Reply)View They are now combined elements and don’t vend the icon as its own element. * Add missing punctuation to accessibility hints * Remove interaction from Profile tab @username and profile note elements These elements open the profile photo url, which is already provided explicitly through the profile photo * Prefer spoiler warning for StatusRowView accessibility label …but place the full, unredacted content in an `AccessibilityCustomContent` field for easy access. Additionally, if VoiceOver is running, an action to expand the warning is also available. * Represent `FollowButton` elements as Toggles to accessibility Since these buttons have two states (though arguable in the case of following, but handled here by not changing the representation if a request is pending), it makes sense to handle them as toggles, so they will be read as “Following, On, <Trait>” * Remove errant comment * Add “Verified” accessibilityValue to profile fields * Fix bug StatusRowView default action bug affecting VoiceOver users Previously, the default (‘Activate’) action for VoiceOver users would be to share a link to the toot, rather than navigate to its detail. It’s hard to say exactly what caused this, but the root was the inclusion of the `contextMenu` in the `accessibilityActions`. Now, double-tapping on a a non-focused `StatusRowView` will take you to the toot detail. * Add header trait to Profile tab display name and familiar followers These stand out as being header-like in presentation and represent the beginning of specific parts of the screen. * Add conditional accessibility modifier to Profile tab user-defined fields that opens the correct link * Add accessibility container that contextualises the user-defined fields When VoiceOver users first enter a user-defined field, the container label will be read out before the element’s spoken description. * Improve StatusRowView combined accessibility label It will now start with: “X boosted Y”, “X replied to @Y”, or “X…” depending on the context of the toot. * Change familiar follows thumbnail to a Button; add display name as accessibility label Previously, this button had no context, and would just be a series of images with nothing to allow users to disambiguate them. * Revert changes from ZStack with tap gesture to Button Using a Button for this purpose caused high weirdness in tap zones. Basically everything down to the familiar followers triggered both image buttons. * Add image alt text to StatusRowView and StatusRowMediaPreviewView Previously, there was no way for the intended audience for the alt text to find said text. There is a tap gesture on each image in the focused status row, but this is not advertised to the user. Now, the first image’s alt text is read as part of the non-focused, combined representation, and each image has its own alt text attributed in the focused representation. * Add Profile tab accessibility labels to indicate private/bot/muted/blocked accounts Previously, the icon did not have any accessible representation (an empty text string). * Add header trait to Profile “pinned post” * Use the Account.Field.name for the user input label * Replace spaces with commas in StatusRowView.combinedAccessibilityLabel
2023-03-19 15:27:18 +00:00
.accessibilityAddTraits([.isButton, .isImage])
} else {
2023-03-03 11:41:38 +00:00
if isCompact || theme.statusDisplayStyle == .compact {
HStack {
makeAttachmentView(for: 0)
makeAttachmentView(for: 1)
makeAttachmentView(for: 2)
makeAttachmentView(for: 3)
}
2022-12-29 16:22:07 +00:00
} else {
VStack {
HStack {
makeAttachmentView(for: 0)
makeAttachmentView(for: 1)
}
2022-12-29 16:22:07 +00:00
HStack {
makeAttachmentView(for: 2)
makeAttachmentView(for: 3)
}
}
2022-12-17 12:37:46 +00:00
}
}
}
2022-12-22 09:53:36 +00:00
.overlay {
if isHidingMedia {
sensitiveMediaOverlay
.transition(.opacity)
}
2022-12-19 16:18:16 +00:00
}
.alert("status.editor.media.image-description",
2023-03-13 12:38:28 +00:00
isPresented: $isAltAlertDisplayed)
{
Button("alert.button.ok", action: {})
2023-01-03 07:45:27 +00:00
} message: {
Text(altTextDisplayed ?? "")
}
.onAppear {
2023-09-16 12:15:03 +00:00
if sensitive, preferences.autoExpandMedia == .hideSensitive {
isHidingMedia = true
} else if preferences.autoExpandMedia == .hideAll {
isHidingMedia = true
} else {
isHidingMedia = false
}
}
}
2023-01-17 10:36:01 +00:00
2022-12-29 16:22:07 +00:00
@ViewBuilder
private func makeAttachmentView(for index: Int) -> some View {
if attachments.count > index {
makePreview(attachment: attachments[index])
2022-12-29 16:22:07 +00:00
}
}
2023-01-17 10:36:01 +00:00
@ViewBuilder
private func makeFeaturedImagePreview(attachment: MediaAttachment) -> some View {
ZStack(alignment: .bottomLeading) {
2023-02-12 09:53:59 +00:00
let size: CGSize = size(for: attachment) ?? .init(width: imageMaxHeight, height: imageMaxHeight)
let newSize = imageSize(from: size, newWidth: availableWidth - appLayoutWidth)
switch attachment.supportedType {
case .image:
LazyImage(url: attachment.url) { state in
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: newSize.width, height: newSize.height)
.clipped()
.cornerRadius(4)
2023-07-17 17:18:19 +00:00
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(.gray.opacity(0.35), lineWidth: 1)
)
} else {
RoundedRectangle(cornerRadius: 4)
.fill(Color.gray)
.frame(width: newSize.width, height: newSize.height)
}
}
.processors([.resize(size: newSize)])
.frame(width: newSize.width, height: newSize.height)
2023-02-12 15:29:41 +00:00
case .gifv, .video, .audio:
if let url = attachment.url {
2023-10-16 17:08:59 +00:00
MediaUIAttachmentVideoView(viewModel: .init(url: url))
2023-02-12 09:53:59 +00:00
.frame(width: newSize.width, height: newSize.height)
}
case .none:
EmptyView()
}
2023-02-19 14:29:07 +00:00
if !isInCaptureMode, sensitive {
cornerSensitiveButton
}
2023-03-03 11:41:38 +00:00
if !isInCaptureMode, let alt = attachment.description, !alt.isEmpty, !isCompact, preferences.showAltTextForMedia {
Group {
Button {
altTextDisplayed = alt
isAltAlertDisplayed = true
} label: {
Text("status.image.alt-text.abbreviation")
.font(theme.statusDisplayStyle == .compact ? .footnote : .body)
}
.buttonStyle(.borderless)
.padding(4)
.background(.thinMaterial)
.cornerRadius(4)
}
.padding(theme.statusDisplayStyle == .compact ? 0 : 10)
2022-12-27 15:16:25 +00:00
}
}
2022-12-19 16:18:16 +00:00
}
2023-01-17 10:36:01 +00:00
2022-12-19 16:18:16 +00:00
@ViewBuilder
private func makePreview(attachment: MediaAttachment) -> some View {
2023-02-19 15:03:27 +00:00
if let type = attachment.supportedType, !isInCaptureMode {
2022-12-20 07:14:57 +00:00
Group {
GeometryReader { proxy in
switch type {
case .image:
2023-03-03 11:41:38 +00:00
let width = isCompact ? imageMaxHeight : proxy.frame(in: .local).width
2023-02-19 14:29:07 +00:00
let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageMaxHeight))]
2023-01-03 07:45:27 +00:00
ZStack(alignment: .bottomTrailing) {
2023-02-19 15:03:27 +00:00
LazyImage(url: attachment.previewUrl ?? attachment.url) { state in
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: width)
.frame(maxHeight: imageMaxHeight)
.clipped()
.cornerRadius(4)
2023-07-17 17:18:19 +00:00
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(.gray.opacity(0.35), lineWidth: 1)
)
2023-02-19 15:03:27 +00:00
} else if state.isLoading {
RoundedRectangle(cornerRadius: 4)
.fill(Color.gray)
.frame(maxHeight: imageMaxHeight)
.frame(maxWidth: width)
2023-01-03 07:45:27 +00:00
}
}
2023-02-19 15:03:27 +00:00
.processors(processors)
2023-02-19 14:29:07 +00:00
if sensitive, !isInCaptureMode {
cornerSensitiveButton
}
2023-02-19 14:29:07 +00:00
if !isInCaptureMode,
2023-02-21 06:23:42 +00:00
let alt = attachment.description,
2023-02-19 14:29:07 +00:00
!alt.isEmpty,
2023-03-03 11:41:38 +00:00
!isCompact,
2023-02-21 06:23:42 +00:00
preferences.showAltTextForMedia
{
2023-01-03 07:45:27 +00:00
Button {
altTextDisplayed = alt
isAltAlertDisplayed = true
} label: {
Text("status.image.alt-text.abbreviation")
.font(.scaledFootnote)
2023-01-03 07:45:27 +00:00
}
.buttonStyle(.borderless)
2023-01-03 07:45:27 +00:00
.padding(4)
.background(.thinMaterial)
.cornerRadius(4)
2022-12-19 16:18:16 +00:00
}
2022-12-25 06:43:02 +00:00
}
case .gifv, .video, .audio:
if let url = attachment.url {
2023-10-16 17:08:59 +00:00
MediaUIAttachmentVideoView(viewModel: .init(url: url))
2023-03-03 11:41:38 +00:00
.frame(width: isCompact ? imageMaxHeight : proxy.frame(in: .local).width)
2022-12-27 15:16:25 +00:00
.frame(height: imageMaxHeight)
Timeline & Timeline detail accessibility uplift (#1323) * Improve accessibility of StatusPollView Previously, this view did not provide the proper context to indicate that it represented a poll. Now, we’ve added - A container that will stay “Active poll” or “Poll results” when the cursor first hits one of the options; - A prefix to say “Option X of Y” before each option; - A Selected trait on the selected option(s), if present - Consolidating and adding an `.updatesFrequently` trait to the footer view with the countdown. * Add poll description in StatusRowView combinedAccessibilityLabel This largely duplicates the logic in `StatusPollView`. * Improve accessibility of media attachments Previously, the media attachments without alt text would not show up in the consolidated `StatusRowView`, nor would they be meaningfully explained on the status detail screen. Now, they are presented with their attachment type. * Change accessibilityRepresentation of AppAcountsSelectorView * Change Notifications tab title view accessibility representation to Menu Previously it would present as a button * Hide layout `Rectangle`s from accessibility * Consolidate `StatusRowDetailView` accessibility representation * Improve readability of Poll accessibility label * Ensure poll options don’t present as interactive when the poll is finished * Improve accessibility of StatusRowCardView Previously, it would present as four separate elements, including an image without a description, all interactive, none with an interactive trait. Now, it presents as a single element with the `.link` trait * Improve accessibility of StatusRowHeaderView Previously, it had no traits and no actions except inherited ones. Now it presents as a button, triggering its primary action. It also has custom actions corresponding to its context menu * Avoid applying the StatusRowView custom actions to every view when contained * Provide context for the application name * Add pauses to StatusRowView combinedAccessibilityLabel * Hide `TimelineView.scrollToTopView` from accessibility * Set appropriate font style on Notification header After the change the Text needed a `.headline` style to match the prior appearance. * Fix bug in accessibilityRepresentation of TimelineView nav bar title Previously, it would not display the proper label for .remoteLocal filter options. * Ensure that pop-up button nav bar titles are interactive * Ensure TextView responds to Environment.sizeCategory This resolves #1309 * Fix button --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-28 16:48:58 +00:00
.accessibilityAddTraits(.startsMediaSession)
2022-12-27 15:16:25 +00:00
}
2022-12-19 16:18:16 +00:00
}
}
2023-03-03 11:41:38 +00:00
.frame(maxWidth: isCompact ? imageMaxHeight : nil)
.frame(height: imageMaxHeight)
2022-12-20 07:14:57 +00:00
}
2023-02-22 06:04:02 +00:00
// #965: do not create overlapping tappable areas, when multiple images are shown
.contentShape(Rectangle())
2022-12-20 07:14:57 +00:00
.onTapGesture {
2023-10-23 17:12:25 +00:00
if ProcessInfo.processInfo.isMacCatalystApp {
openWindow(value: WindowDestination.mediaViewer(attachments: attachments,
selectedAttachment: attachment))
} else {
quickLook.prepareFor(selectedMediaAttachment: attachment, mediaAttachments: attachments)
}
2022-12-17 12:37:46 +00:00
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(Self.accessibilityLabel(for: attachment))
.accessibilityAddTraits(attachment.supportedType == .image ? [.isImage, .isButton] : .isButton)
2022-12-19 15:01:23 +00:00
}
2022-12-17 12:37:46 +00:00
}
2023-01-17 10:36:01 +00:00
private var sensitiveMediaOverlay: some View {
ZStack {
Rectangle()
.foregroundColor(.clear)
.background(.ultraThinMaterial)
2023-03-03 11:41:38 +00:00
if !isCompact {
Button {
withAnimation {
isHidingMedia = false
}
} label: {
Group {
if sensitive {
Label("status.media.sensitive.show", systemImage: "eye")
} else {
Label("status.media.content.show", systemImage: "eye")
}
}
.foregroundColor(theme.labelColor)
}
.buttonStyle(.borderedProminent)
}
}
}
2023-01-17 10:36:01 +00:00
private var cornerSensitiveButton: some View {
2023-01-22 05:38:30 +00:00
HStack {
Button {
withAnimation {
isHidingMedia = true
}
} label: {
Image(systemName: "eye.slash")
2023-01-22 05:38:30 +00:00
.frame(minHeight: 21) // Match the alt button in case it is also present
}
.padding(10)
.buttonStyle(.borderedProminent)
Spacer()
}
}
Profile tab accessibility uplift (#1274) * Combine `joinedAtView` into one accessibility element Previously, the calendar image was visible with a nonsensical label. We use the `.combine` operator here to maintain the proper string formatting of the date. * Improve the accessibility of the AccountDetailHeaderView Previously, this image had no description and no indication that it had an associated interaction. Now, we wrap it in a button that performs the tap gesture action, and remove the element altogether if there is no avatar image set. This commit also handles the checkmark for supporter users * Tweak accessibility of Profile CustomInfoLabels This commit: - Reverses the order of title and value - Sets the value as an `accessibilityValue` - Adds a hint indicating what the button does, as they perform slightly different actions * Make Profile tab header image into a Button This element has an action associated with it (quicklook), so it makes more sense to have it as a button, and hide it if the user does not have an image set. Without the action it would have been considered decorative and should be hidden. * Change accessibilityLabel of Profile tab nav bar item to ‘Options’ “More” is considered overly generic. This commit also adds two additional user input label options * Add accessibility labels for the Profile tab `Picker` Previously, these labels were the default accessibility label provided by the SF symbol, that almost, but not quite, made sense * Remove StatusRowView swipe actions if VoiceOver is running These swipe actions are automagically added to the accessibility element’s custom actions, in addition to the ones already there, which means that there is a significant (and confusing) amount of doubling up going on. * Fix typo in StatusRowView.accessibilityActions * Add accessibilityLabels to all StatusRowActionsView actions * Provide explicit combined accessibility label for unfocused StatusRowView Previously, this was a synthesized label, which read the elements in their traversal order, and didn’t provide any context for which of the three numbers corresponded to replies, boosts or favourites. Now, we create an explicit combined label when the post isn’t being viewed by itself. * Improve accessibility of StatusRow(Reblog|Reply)View They are now combined elements and don’t vend the icon as its own element. * Add missing punctuation to accessibility hints * Remove interaction from Profile tab @username and profile note elements These elements open the profile photo url, which is already provided explicitly through the profile photo * Prefer spoiler warning for StatusRowView accessibility label …but place the full, unredacted content in an `AccessibilityCustomContent` field for easy access. Additionally, if VoiceOver is running, an action to expand the warning is also available. * Represent `FollowButton` elements as Toggles to accessibility Since these buttons have two states (though arguable in the case of following, but handled here by not changing the representation if a request is pending), it makes sense to handle them as toggles, so they will be read as “Following, On, <Trait>” * Remove errant comment * Add “Verified” accessibilityValue to profile fields * Fix bug StatusRowView default action bug affecting VoiceOver users Previously, the default (‘Activate’) action for VoiceOver users would be to share a link to the toot, rather than navigate to its detail. It’s hard to say exactly what caused this, but the root was the inclusion of the `contextMenu` in the `accessibilityActions`. Now, double-tapping on a a non-focused `StatusRowView` will take you to the toot detail. * Add header trait to Profile tab display name and familiar followers These stand out as being header-like in presentation and represent the beginning of specific parts of the screen. * Add conditional accessibility modifier to Profile tab user-defined fields that opens the correct link * Add accessibility container that contextualises the user-defined fields When VoiceOver users first enter a user-defined field, the container label will be read out before the element’s spoken description. * Improve StatusRowView combined accessibility label It will now start with: “X boosted Y”, “X replied to @Y”, or “X…” depending on the context of the toot. * Change familiar follows thumbnail to a Button; add display name as accessibility label Previously, this button had no context, and would just be a series of images with nothing to allow users to disambiguate them. * Revert changes from ZStack with tap gesture to Button Using a Button for this purpose caused high weirdness in tap zones. Basically everything down to the familiar followers triggered both image buttons. * Add image alt text to StatusRowView and StatusRowMediaPreviewView Previously, there was no way for the intended audience for the alt text to find said text. There is a tap gesture on each image in the focused status row, but this is not advertised to the user. Now, the first image’s alt text is read as part of the non-focused, combined representation, and each image has its own alt text attributed in the focused representation. * Add Profile tab accessibility labels to indicate private/bot/muted/blocked accounts Previously, the icon did not have any accessible representation (an empty text string). * Add header trait to Profile “pinned post” * Use the Account.Field.name for the user input label * Replace spaces with commas in StatusRowView.combinedAccessibilityLabel
2023-03-19 15:27:18 +00:00
private static func accessibilityLabel(for attachment: MediaAttachment) -> Text {
Profile tab accessibility uplift (#1274) * Combine `joinedAtView` into one accessibility element Previously, the calendar image was visible with a nonsensical label. We use the `.combine` operator here to maintain the proper string formatting of the date. * Improve the accessibility of the AccountDetailHeaderView Previously, this image had no description and no indication that it had an associated interaction. Now, we wrap it in a button that performs the tap gesture action, and remove the element altogether if there is no avatar image set. This commit also handles the checkmark for supporter users * Tweak accessibility of Profile CustomInfoLabels This commit: - Reverses the order of title and value - Sets the value as an `accessibilityValue` - Adds a hint indicating what the button does, as they perform slightly different actions * Make Profile tab header image into a Button This element has an action associated with it (quicklook), so it makes more sense to have it as a button, and hide it if the user does not have an image set. Without the action it would have been considered decorative and should be hidden. * Change accessibilityLabel of Profile tab nav bar item to ‘Options’ “More” is considered overly generic. This commit also adds two additional user input label options * Add accessibility labels for the Profile tab `Picker` Previously, these labels were the default accessibility label provided by the SF symbol, that almost, but not quite, made sense * Remove StatusRowView swipe actions if VoiceOver is running These swipe actions are automagically added to the accessibility element’s custom actions, in addition to the ones already there, which means that there is a significant (and confusing) amount of doubling up going on. * Fix typo in StatusRowView.accessibilityActions * Add accessibilityLabels to all StatusRowActionsView actions * Provide explicit combined accessibility label for unfocused StatusRowView Previously, this was a synthesized label, which read the elements in their traversal order, and didn’t provide any context for which of the three numbers corresponded to replies, boosts or favourites. Now, we create an explicit combined label when the post isn’t being viewed by itself. * Improve accessibility of StatusRow(Reblog|Reply)View They are now combined elements and don’t vend the icon as its own element. * Add missing punctuation to accessibility hints * Remove interaction from Profile tab @username and profile note elements These elements open the profile photo url, which is already provided explicitly through the profile photo * Prefer spoiler warning for StatusRowView accessibility label …but place the full, unredacted content in an `AccessibilityCustomContent` field for easy access. Additionally, if VoiceOver is running, an action to expand the warning is also available. * Represent `FollowButton` elements as Toggles to accessibility Since these buttons have two states (though arguable in the case of following, but handled here by not changing the representation if a request is pending), it makes sense to handle them as toggles, so they will be read as “Following, On, <Trait>” * Remove errant comment * Add “Verified” accessibilityValue to profile fields * Fix bug StatusRowView default action bug affecting VoiceOver users Previously, the default (‘Activate’) action for VoiceOver users would be to share a link to the toot, rather than navigate to its detail. It’s hard to say exactly what caused this, but the root was the inclusion of the `contextMenu` in the `accessibilityActions`. Now, double-tapping on a a non-focused `StatusRowView` will take you to the toot detail. * Add header trait to Profile tab display name and familiar followers These stand out as being header-like in presentation and represent the beginning of specific parts of the screen. * Add conditional accessibility modifier to Profile tab user-defined fields that opens the correct link * Add accessibility container that contextualises the user-defined fields When VoiceOver users first enter a user-defined field, the container label will be read out before the element’s spoken description. * Improve StatusRowView combined accessibility label It will now start with: “X boosted Y”, “X replied to @Y”, or “X…” depending on the context of the toot. * Change familiar follows thumbnail to a Button; add display name as accessibility label Previously, this button had no context, and would just be a series of images with nothing to allow users to disambiguate them. * Revert changes from ZStack with tap gesture to Button Using a Button for this purpose caused high weirdness in tap zones. Basically everything down to the familiar followers triggered both image buttons. * Add image alt text to StatusRowView and StatusRowMediaPreviewView Previously, there was no way for the intended audience for the alt text to find said text. There is a tap gesture on each image in the focused status row, but this is not advertised to the user. Now, the first image’s alt text is read as part of the non-focused, combined representation, and each image has its own alt text attributed in the focused representation. * Add Profile tab accessibility labels to indicate private/bot/muted/blocked accounts Previously, the icon did not have any accessible representation (an empty text string). * Add header trait to Profile “pinned post” * Use the Account.Field.name for the user input label * Replace spaces with commas in StatusRowView.combinedAccessibilityLabel
2023-03-19 15:27:18 +00:00
if let altText = attachment.description {
2023-09-16 12:15:03 +00:00
Text("accessibility.image.alt-text-\(altText)")
Timeline & Timeline detail accessibility uplift (#1323) * Improve accessibility of StatusPollView Previously, this view did not provide the proper context to indicate that it represented a poll. Now, we’ve added - A container that will stay “Active poll” or “Poll results” when the cursor first hits one of the options; - A prefix to say “Option X of Y” before each option; - A Selected trait on the selected option(s), if present - Consolidating and adding an `.updatesFrequently` trait to the footer view with the countdown. * Add poll description in StatusRowView combinedAccessibilityLabel This largely duplicates the logic in `StatusPollView`. * Improve accessibility of media attachments Previously, the media attachments without alt text would not show up in the consolidated `StatusRowView`, nor would they be meaningfully explained on the status detail screen. Now, they are presented with their attachment type. * Change accessibilityRepresentation of AppAcountsSelectorView * Change Notifications tab title view accessibility representation to Menu Previously it would present as a button * Hide layout `Rectangle`s from accessibility * Consolidate `StatusRowDetailView` accessibility representation * Improve readability of Poll accessibility label * Ensure poll options don’t present as interactive when the poll is finished * Improve accessibility of StatusRowCardView Previously, it would present as four separate elements, including an image without a description, all interactive, none with an interactive trait. Now, it presents as a single element with the `.link` trait * Improve accessibility of StatusRowHeaderView Previously, it had no traits and no actions except inherited ones. Now it presents as a button, triggering its primary action. It also has custom actions corresponding to its context menu * Avoid applying the StatusRowView custom actions to every view when contained * Provide context for the application name * Add pauses to StatusRowView combinedAccessibilityLabel * Hide `TimelineView.scrollToTopView` from accessibility * Set appropriate font style on Notification header After the change the Text needed a `.headline` style to match the prior appearance. * Fix bug in accessibilityRepresentation of TimelineView nav bar title Previously, it would not display the proper label for .remoteLocal filter options. * Ensure that pop-up button nav bar titles are interactive * Ensure TextView responds to Environment.sizeCategory This resolves #1309 * Fix button --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-28 16:48:58 +00:00
} else if let typeDescription = attachment.localizedTypeDescription {
2023-09-16 12:15:03 +00:00
Text(typeDescription)
Profile tab accessibility uplift (#1274) * Combine `joinedAtView` into one accessibility element Previously, the calendar image was visible with a nonsensical label. We use the `.combine` operator here to maintain the proper string formatting of the date. * Improve the accessibility of the AccountDetailHeaderView Previously, this image had no description and no indication that it had an associated interaction. Now, we wrap it in a button that performs the tap gesture action, and remove the element altogether if there is no avatar image set. This commit also handles the checkmark for supporter users * Tweak accessibility of Profile CustomInfoLabels This commit: - Reverses the order of title and value - Sets the value as an `accessibilityValue` - Adds a hint indicating what the button does, as they perform slightly different actions * Make Profile tab header image into a Button This element has an action associated with it (quicklook), so it makes more sense to have it as a button, and hide it if the user does not have an image set. Without the action it would have been considered decorative and should be hidden. * Change accessibilityLabel of Profile tab nav bar item to ‘Options’ “More” is considered overly generic. This commit also adds two additional user input label options * Add accessibility labels for the Profile tab `Picker` Previously, these labels were the default accessibility label provided by the SF symbol, that almost, but not quite, made sense * Remove StatusRowView swipe actions if VoiceOver is running These swipe actions are automagically added to the accessibility element’s custom actions, in addition to the ones already there, which means that there is a significant (and confusing) amount of doubling up going on. * Fix typo in StatusRowView.accessibilityActions * Add accessibilityLabels to all StatusRowActionsView actions * Provide explicit combined accessibility label for unfocused StatusRowView Previously, this was a synthesized label, which read the elements in their traversal order, and didn’t provide any context for which of the three numbers corresponded to replies, boosts or favourites. Now, we create an explicit combined label when the post isn’t being viewed by itself. * Improve accessibility of StatusRow(Reblog|Reply)View They are now combined elements and don’t vend the icon as its own element. * Add missing punctuation to accessibility hints * Remove interaction from Profile tab @username and profile note elements These elements open the profile photo url, which is already provided explicitly through the profile photo * Prefer spoiler warning for StatusRowView accessibility label …but place the full, unredacted content in an `AccessibilityCustomContent` field for easy access. Additionally, if VoiceOver is running, an action to expand the warning is also available. * Represent `FollowButton` elements as Toggles to accessibility Since these buttons have two states (though arguable in the case of following, but handled here by not changing the representation if a request is pending), it makes sense to handle them as toggles, so they will be read as “Following, On, <Trait>” * Remove errant comment * Add “Verified” accessibilityValue to profile fields * Fix bug StatusRowView default action bug affecting VoiceOver users Previously, the default (‘Activate’) action for VoiceOver users would be to share a link to the toot, rather than navigate to its detail. It’s hard to say exactly what caused this, but the root was the inclusion of the `contextMenu` in the `accessibilityActions`. Now, double-tapping on a a non-focused `StatusRowView` will take you to the toot detail. * Add header trait to Profile tab display name and familiar followers These stand out as being header-like in presentation and represent the beginning of specific parts of the screen. * Add conditional accessibility modifier to Profile tab user-defined fields that opens the correct link * Add accessibility container that contextualises the user-defined fields When VoiceOver users first enter a user-defined field, the container label will be read out before the element’s spoken description. * Improve StatusRowView combined accessibility label It will now start with: “X boosted Y”, “X replied to @Y”, or “X…” depending on the context of the toot. * Change familiar follows thumbnail to a Button; add display name as accessibility label Previously, this button had no context, and would just be a series of images with nothing to allow users to disambiguate them. * Revert changes from ZStack with tap gesture to Button Using a Button for this purpose caused high weirdness in tap zones. Basically everything down to the familiar followers triggered both image buttons. * Add image alt text to StatusRowView and StatusRowMediaPreviewView Previously, there was no way for the intended audience for the alt text to find said text. There is a tap gesture on each image in the focused status row, but this is not advertised to the user. Now, the first image’s alt text is read as part of the non-focused, combined representation, and each image has its own alt text attributed in the focused representation. * Add Profile tab accessibility labels to indicate private/bot/muted/blocked accounts Previously, the icon did not have any accessible representation (an empty text string). * Add header trait to Profile “pinned post” * Use the Account.Field.name for the user input label * Replace spaces with commas in StatusRowView.combinedAccessibilityLabel
2023-03-19 15:27:18 +00:00
} else {
2023-09-16 12:15:03 +00:00
Text("accessibility.tabs.profile.picker.media")
Profile tab accessibility uplift (#1274) * Combine `joinedAtView` into one accessibility element Previously, the calendar image was visible with a nonsensical label. We use the `.combine` operator here to maintain the proper string formatting of the date. * Improve the accessibility of the AccountDetailHeaderView Previously, this image had no description and no indication that it had an associated interaction. Now, we wrap it in a button that performs the tap gesture action, and remove the element altogether if there is no avatar image set. This commit also handles the checkmark for supporter users * Tweak accessibility of Profile CustomInfoLabels This commit: - Reverses the order of title and value - Sets the value as an `accessibilityValue` - Adds a hint indicating what the button does, as they perform slightly different actions * Make Profile tab header image into a Button This element has an action associated with it (quicklook), so it makes more sense to have it as a button, and hide it if the user does not have an image set. Without the action it would have been considered decorative and should be hidden. * Change accessibilityLabel of Profile tab nav bar item to ‘Options’ “More” is considered overly generic. This commit also adds two additional user input label options * Add accessibility labels for the Profile tab `Picker` Previously, these labels were the default accessibility label provided by the SF symbol, that almost, but not quite, made sense * Remove StatusRowView swipe actions if VoiceOver is running These swipe actions are automagically added to the accessibility element’s custom actions, in addition to the ones already there, which means that there is a significant (and confusing) amount of doubling up going on. * Fix typo in StatusRowView.accessibilityActions * Add accessibilityLabels to all StatusRowActionsView actions * Provide explicit combined accessibility label for unfocused StatusRowView Previously, this was a synthesized label, which read the elements in their traversal order, and didn’t provide any context for which of the three numbers corresponded to replies, boosts or favourites. Now, we create an explicit combined label when the post isn’t being viewed by itself. * Improve accessibility of StatusRow(Reblog|Reply)View They are now combined elements and don’t vend the icon as its own element. * Add missing punctuation to accessibility hints * Remove interaction from Profile tab @username and profile note elements These elements open the profile photo url, which is already provided explicitly through the profile photo * Prefer spoiler warning for StatusRowView accessibility label …but place the full, unredacted content in an `AccessibilityCustomContent` field for easy access. Additionally, if VoiceOver is running, an action to expand the warning is also available. * Represent `FollowButton` elements as Toggles to accessibility Since these buttons have two states (though arguable in the case of following, but handled here by not changing the representation if a request is pending), it makes sense to handle them as toggles, so they will be read as “Following, On, <Trait>” * Remove errant comment * Add “Verified” accessibilityValue to profile fields * Fix bug StatusRowView default action bug affecting VoiceOver users Previously, the default (‘Activate’) action for VoiceOver users would be to share a link to the toot, rather than navigate to its detail. It’s hard to say exactly what caused this, but the root was the inclusion of the `contextMenu` in the `accessibilityActions`. Now, double-tapping on a a non-focused `StatusRowView` will take you to the toot detail. * Add header trait to Profile tab display name and familiar followers These stand out as being header-like in presentation and represent the beginning of specific parts of the screen. * Add conditional accessibility modifier to Profile tab user-defined fields that opens the correct link * Add accessibility container that contextualises the user-defined fields When VoiceOver users first enter a user-defined field, the container label will be read out before the element’s spoken description. * Improve StatusRowView combined accessibility label It will now start with: “X boosted Y”, “X replied to @Y”, or “X…” depending on the context of the toot. * Change familiar follows thumbnail to a Button; add display name as accessibility label Previously, this button had no context, and would just be a series of images with nothing to allow users to disambiguate them. * Revert changes from ZStack with tap gesture to Button Using a Button for this purpose caused high weirdness in tap zones. Basically everything down to the familiar followers triggered both image buttons. * Add image alt text to StatusRowView and StatusRowMediaPreviewView Previously, there was no way for the intended audience for the alt text to find said text. There is a tap gesture on each image in the focused status row, but this is not advertised to the user. Now, the first image’s alt text is read as part of the non-focused, combined representation, and each image has its own alt text attributed in the focused representation. * Add Profile tab accessibility labels to indicate private/bot/muted/blocked accounts Previously, the icon did not have any accessible representation (an empty text string). * Add header trait to Profile “pinned post” * Use the Account.Field.name for the user input label * Replace spaces with commas in StatusRowView.combinedAccessibilityLabel
2023-03-19 15:27:18 +00:00
}
}
}