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

533 lines
16 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-11-01 17:58:44 +00:00
import MediaUI
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
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
@Environment(\.isMediaCompact) private var isCompact: Bool
@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-17 10:36:01 +00:00
init(attachments: [MediaAttachment], sensitive: Bool) {
self.attachments = attachments
self.sensitive = sensitive
}
2024-02-14 11:48:14 +00:00
#if targetEnvironment(macCatalyst)
private var showsScrollIndicators: Bool { attachments.count > 1 }
private var scrollBottomPadding: CGFloat?
#else
private var showsScrollIndicators: Bool = false
private var scrollBottomPadding: CGFloat? = 0
#endif
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
}
2023-12-07 17:48:18 +00:00
return 300
}
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 {
FeaturedImagePreView(
attachment: attachments[0],
2024-02-14 11:48:14 +00:00
maxSize: imageMaxHeight == 300
? nil
: CGSize(width: imageMaxHeight, height: imageMaxHeight),
sensitive: sensitive
)
.padding(.horizontal, .layoutPadding)
.accessibilityElement(children: .ignore)
.accessibilityLabel(Self.accessibilityLabel(for: attachments[0]))
.accessibilityAddTraits([.isButton, .isImage])
.onTapGesture { tabAction(for: 0) }
} else {
ScrollView(.horizontal, showsIndicators: showsScrollIndicators) {
HStack {
2024-02-05 13:24:29 +00:00
ForEach(attachments) { attachment in
makeAttachmentView(attachment)
}
}
.padding(.bottom, scrollBottomPadding)
.padding(.horizontal, .layoutPadding)
2022-12-17 12:37:46 +00:00
}
}
}
.padding(.horizontal, -1 * .layoutPadding)
}
@ViewBuilder
2024-02-05 13:24:29 +00:00
private func makeAttachmentView(_ attachement: MediaAttachment) -> some View {
if let data = DisplayData(from: attachement) {
MediaPreview(
sensitive: sensitive,
imageMaxHeight: imageMaxHeight,
displayData: data
)
2024-02-14 11:48:14 +00:00
.onTapGesture {
2024-02-05 13:24:29 +00:00
if let index = attachments.firstIndex(where: { $0.id == attachement.id }) {
tabAction(for: index)
}
}
2024-02-06 08:15:22 +00:00
#if os(visionOS)
.hoverEffect()
#endif
2023-01-03 07:45:27 +00:00
}
}
private func tabAction(for index: Int) {
2024-01-09 12:28:57 +00:00
#if targetEnvironment(macCatalyst) || os(visionOS)
openWindow(
2023-11-14 18:48:14 +00:00
value: WindowDestinationMedia.mediaViewer(
attachments: attachments,
selectedAttachment: attachments[index]
)
)
2023-12-18 07:22:59 +00:00
#else
quickLook.prepareFor(
selectedMediaAttachment: attachments[index],
mediaAttachments: attachments
)
2023-12-18 07:22:59 +00:00
#endif
}
2023-01-17 10:36:01 +00:00
private static func accessibilityLabel(for attachment: MediaAttachment) -> Text {
if let altText = attachment.description {
Text("accessibility.image.alt-text-\(altText)")
} else if let typeDescription = attachment.localizedTypeDescription {
Text(typeDescription)
} else {
Text("accessibility.tabs.profile.picker.media")
2022-12-29 16:22:07 +00:00
}
}
}
2023-01-17 10:36:01 +00:00
private struct MediaPreview: View {
let sensitive: Bool
let imageMaxHeight: CGFloat
let displayData: DisplayData
var body: some View {
Group {
switch displayData.type {
case .image:
2023-12-18 07:22:59 +00:00
LazyResizableImage(url: displayData.previewUrl) { state, _ in
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
2023-12-27 15:07:16 +00:00
.frame(width: displayData.isLandscape ? imageMaxHeight * 1.2 : imageMaxHeight / 1.5,
height: imageMaxHeight)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(.gray.opacity(0.35), lineWidth: 1)
)
} else if state.isLoading {
RoundedRectangle(cornerRadius: 10)
.fill(Color.gray)
}
}
.overlay {
BlurOverLay(sensitive: sensitive, font: .scaledFootnote)
}
.overlay {
AltTextButton(text: displayData.description, font: .scaledFootnote)
}
case .av:
MediaUIAttachmentVideoView(viewModel: .init(url: displayData.url))
.accessibilityAddTraits(.startsMediaSession)
}
}
.frame(width: displayData.isLandscape ? imageMaxHeight * 1.2 : imageMaxHeight / 1.5,
height: imageMaxHeight)
.clipped()
.cornerRadius(10)
// #965: do not create overlapping tappable areas, when multiple images are shown
.contentShape(Rectangle())
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text(displayData.accessibilityText))
.accessibilityAddTraits(displayData.type == .image ? [.isImage, .isButton] : .isButton)
}
}
@MainActor
struct BlurOverLay: View {
let sensitive: Bool
let font: Font?
@State private var isFrameExpanded = true
@Environment(Theme.self) private var theme
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@Environment(UserPreferences.self) private var preferences
2024-02-02 17:39:39 +00:00
@Environment(\.isMediaCompact) private var isCompact: Bool
@Namespace var buttonSpace
var body: some View {
if hasOverlay {
ZStack {
Rectangle()
.foregroundColor(.clear)
.background(.ultraThinMaterial)
.frame(
width: isFrameExpanded ? nil : 0,
2023-11-07 10:24:03 +00:00
height: isFrameExpanded ? nil : 0
)
if !isCompact {
2023-11-07 10:24:03 +00:00
Button {
2023-12-31 12:28:27 +00:00
withAnimation(.spring) {
isFrameExpanded.toggle()
2023-11-07 10:24:03 +00:00
}
} label: {
2023-12-31 12:28:27 +00:00
if isFrameExpanded {
2023-11-07 10:24:03 +00:00
ViewThatFits(in: .horizontal) {
HStack {
Image(systemName: "eye")
2023-12-31 12:28:27 +00:00
.matchedGeometryEffect(id: "eye", in: buttonSpace)
2023-11-07 10:24:03 +00:00
Text(sensitive ? "status.media.sensitive.show" : "status.media.content.show")
2023-01-03 07:45:27 +00:00
}
2023-11-07 10:24:03 +00:00
HStack {
Image(systemName: "eye")
2023-12-31 12:28:27 +00:00
.matchedGeometryEffect(id: "eye", in: buttonSpace)
2023-11-07 10:24:03 +00:00
Text("Show")
}
Image(systemName: "eye")
2023-12-31 12:28:27 +00:00
.matchedGeometryEffect(id: "eye", in: buttonSpace)
2022-12-19 16:18:16 +00:00
}
2023-11-07 10:24:03 +00:00
.lineLimit(1)
.foregroundColor(theme.contrastingTintColor)
2023-11-07 10:24:03 +00:00
} else {
Image(systemName: "eye.slash")
2023-12-31 12:28:27 +00:00
.transition(.opacity)
.matchedGeometryEffect(id: "eye", in: buttonSpace)
2022-12-25 06:43:02 +00:00
}
2023-11-07 10:24:03 +00:00
}
.foregroundColor(theme.labelColor)
.buttonStyle(.borderedProminent)
.padding(theme.statusDisplayStyle == .compact ? 0 : 10)
2022-12-19 16:18:16 +00:00
}
2022-12-20 07:14:57 +00:00
}
.font(font)
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: isFrameExpanded ? .center : .bottomLeading
)
} else {
EmptyView()
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 hasOverlay: Bool {
switch (sensitive, preferences.autoExpandMedia) {
case (_, .hideAll), (true, .hideSensitive):
switch isInCaptureMode {
case true: false
case false: true
}
default: false
}
}
}
2023-01-17 10:36:01 +00:00
struct AltTextButton: View {
let text: String?
let font: Font?
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
2024-02-02 17:39:39 +00:00
@Environment(\.isMediaCompact) private var isCompact: Bool
@Environment(UserPreferences.self) private var preferences
@Environment(\.locale) private var locale
@Environment(Theme.self) private var theme
@State private var isDisplayingAlert = false
var body: some View {
if !isInCaptureMode,
2023-11-07 10:24:03 +00:00
let text,
!text.isEmpty,
!isCompact,
preferences.showAltTextForMedia
{
Button {
isDisplayingAlert = true
} label: {
ZStack {
// use to sync button with show/hide content button
Image(systemName: "eye.slash").opacity(0)
2023-11-07 10:24:03 +00:00
Text("status.image.alt-text.abbreviation")
}
}
.buttonStyle(.borderless)
.padding(EdgeInsets(top: 5, leading: 7, bottom: 5, trailing: 7))
.background(.thinMaterial)
2024-02-06 08:15:22 +00:00
#if os(visionOS)
2024-02-14 11:48:14 +00:00
.clipShape(Capsule())
2024-02-06 08:15:22 +00:00
#endif
2024-02-14 11:48:14 +00:00
.cornerRadius(4)
.padding(theme.statusDisplayStyle == .compact ? 0 : 10)
.alert(
"status.editor.media.image-description",
isPresented: $isDisplayingAlert
) {
Button("alert.button.ok", action: {})
} message: {
Text(text)
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .bottomTrailing
)
}
}
}
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 struct DisplayData: Identifiable, Hashable {
let id: String
let url: URL
let previewUrl: URL?
let description: String?
let type: DisplayType
let accessibilityText: String
let isLandscape: Bool
init?(from attachment: MediaAttachment) {
guard let url = attachment.url else { return nil }
guard let type = attachment.supportedType else { return nil }
id = attachment.id
self.url = url
2023-11-07 10:24:03 +00:00
previewUrl = attachment.previewUrl ?? attachment.url
description = attachment.description
self.type = DisplayType(from: type)
accessibilityText = Self.getAccessibilityString(from: attachment)
isLandscape = (attachment.meta?.original?.width ?? 0) > (attachment.meta?.original?.height ?? 0)
}
private static func getAccessibilityString(from attachment: MediaAttachment) -> String {
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 {
"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 {
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 {
"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
}
}
}
private enum DisplayType {
case image
case av
init(from attachmentType: MediaAttachment.SupportedType) {
switch attachmentType {
case .image:
self = .image
case .video, .gifv, .audio:
self = .av
}
}
}
struct StatusRowMediaPreviewView_Previews: PreviewProvider {
static var previews: some View {
WrapperForPreview()
}
}
struct WrapperForPreview: View {
@State private var isCompact = false
@State private var isInCaptureMode = false
var body: some View {
VStack {
ScrollView {
VStack {
2023-11-07 10:24:03 +00:00
ForEach(1 ..< 5) { number in
VStack {
Text("Preview for \(number) item(s)")
StatusRowMediaPreviewView(
attachments: Array(repeating: Self.attachment, count: number),
sensitive: true
)
}
.padding()
.border(.red)
}
}
}
.environment(SceneDelegate())
.environment(UserPreferences.shared)
.environment(QuickLook.shared)
.environment(Theme.shared)
2024-02-02 17:39:39 +00:00
.environment(\.isMediaCompact, isCompact)
.environment(\.isInCaptureMode, isInCaptureMode)
Divider()
Toggle("Compact Mode", isOn: $isCompact.animation())
Toggle("Capture Mode", isOn: $isInCaptureMode)
}
.padding()
}
2023-11-07 10:24:03 +00:00
private static let url = URL(string: "https://www.upwork.com/catalog-images/c5dffd9b5094556adb26e0a193a1c494")!
private static let attachment = MediaAttachment.imageWith(url: url)
private static let local = Locale(identifier: "en")
}
@MainActor
private struct FeaturedImagePreView: View {
let attachment: MediaAttachment
let maxSize: CGSize?
let sensitive: Bool
@Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool
@Environment(Theme.self) private var theme
@Environment(\.isModal) private var isModal: Bool
private var originalWidth: CGFloat {
CGFloat(attachment.meta?.original?.width ?? 300)
}
private var originalHeight: CGFloat {
CGFloat(attachment.meta?.original?.height ?? 300)
}
var body: some View {
if let url = attachment.url {
_Layout(originalWidth: originalWidth, originalHeight: originalHeight, maxSize: maxSize) {
Group {
RoundedRectangle(cornerRadius: 10).fill(Color.gray)
.overlay {
switch attachment.supportedType {
case .image:
LazyResizableImage(url: attachment.url) { state, _ in
if let image = state.image {
image
.resizable()
.scaledToFill()
} else {
RoundedRectangle(cornerRadius: 10).fill(Color.gray)
}
}
case .gifv, .video, .audio:
MediaUIAttachmentVideoView(viewModel: .init(url: url))
default:
EmptyView()
}
}
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(.gray.opacity(0.35), lineWidth: 1)
)
2024-02-14 11:48:14 +00:00
#if os(visionOS)
2024-02-06 08:15:22 +00:00
.hoverEffect()
2024-02-14 11:48:14 +00:00
#endif
}
}
.overlay {
BlurOverLay(sensitive: sensitive, font: .scaledFootnote)
}
.overlay {
AltTextButton(
text: attachment.description,
font: theme.statusDisplayStyle == .compact ? .footnote : .body
)
}
.clipped()
.cornerRadius(10)
}
}
private struct _Layout: Layout {
let originalWidth: CGFloat
let originalHeight: CGFloat
let maxSize: CGSize?
init(originalWidth: CGFloat?, originalHeight: CGFloat?, maxSize: CGSize?) {
self.originalWidth = originalWidth ?? 200
self.originalHeight = originalHeight ?? 200
self.maxSize = maxSize
}
2024-02-14 11:48:14 +00:00
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) -> CGSize {
guard !subviews.isEmpty else { return CGSize.zero }
if let maxSize { return maxSize }
return calculateSize(proposal)
}
2024-02-14 11:48:14 +00:00
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) {
guard let view = subviews.first else { return }
let size = if let maxSize { maxSize } else { calculateSize(proposal) }
view.place(at: bounds.origin, proposal: ProposedViewSize(size))
}
private func calculateSize(_ proposal: ProposedViewSize) -> CGSize {
var size: CGSize
switch (proposal.width, proposal.height) {
case (0, _), (_, 0):
size = CGSize.zero
case (nil, nil), (nil, .some(.infinity)), (.some(.infinity), .some(.infinity)), (.some(.infinity), nil):
size = CGSize(width: originalWidth, height: originalWidth)
case let (nil, .some(height)), let (.some(.infinity), .some(height)):
let minHeight = min(height, originalWidth)
if originalHeight == 0 {
size = CGSize.zero
} else {
size = CGSize(width: originalWidth * minHeight / originalHeight, height: minHeight)
}
case let (.some(width), .some(.infinity)), let (.some(width), nil):
if originalWidth == 0 {
size = CGSize(width: width, height: width)
} else {
size = CGSize(width: width, height: width / originalWidth * originalHeight)
}
case let (.some(width), .some(height)):
// intrinsic size of image fits just fine
if originalWidth <= width, originalHeight <= height {
size = CGSize(width: originalWidth, height: originalHeight)
}
// shrink image proportionally to fit inside the box
let xRatio = width / originalWidth
let yRatio = height / originalHeight
// use small ratio to fit the image in
if xRatio < yRatio {
size = CGSize(width: width, height: originalHeight * xRatio)
} else {
size = CGSize(width: originalWidth * yRatio, height: height)
}
}
return CGSize(width: max(size.width, 200), height: min(size.height, 450))
}
}
}