From 079792784cbcbac2db87a14c1e662e8db41fe540 Mon Sep 17 00:00:00 2001 From: CMK Date: Fri, 3 Dec 2021 20:23:40 +0800 Subject: [PATCH] feat: patch some VoiceOver issues. #309 --- .../xcschemes/xcschememanagement.plist | 8 +++--- .../Section/Status/NotificationSection.swift | 28 +++++++++++++++++++ .../Section/Status/PollSection.swift | 9 ++++++ .../Section/Status/StatusSection.swift | 8 +++++- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist index aa6a21a4..913a8fdb 100644 --- a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ AppShared.xcscheme_^#shared#^_ orderHint - 47 + 37 CoreDataStack.xcscheme_^#shared#^_ orderHint - 46 + 36 Mastodon - ASDK.xcscheme_^#shared#^_ @@ -102,7 +102,7 @@ MastodonIntent.xcscheme_^#shared#^_ orderHint - 45 + 38 MastodonIntents.xcscheme_^#shared#^_ @@ -122,7 +122,7 @@ ShareActionExtension.xcscheme_^#shared#^_ orderHint - 48 + 39 SuppressBuildableAutocreation diff --git a/Mastodon/Diffiable/Section/Status/NotificationSection.swift b/Mastodon/Diffiable/Section/Status/NotificationSection.swift index 22283a47..86478500 100644 --- a/Mastodon/Diffiable/Section/Status/NotificationSection.swift +++ b/Mastodon/Diffiable/Section/Status/NotificationSection.swift @@ -45,6 +45,8 @@ extension NotificationSection { attribute: attribute ) cell.delegate = delegate + cell.isAccessibilityElement = true + NotificationSection.configureStatusAccessibilityLabel(cell: cell) return cell case .notificationStatus(objectID: let objectID, attribute: let attribute): @@ -215,4 +217,30 @@ extension NotificationSection { cell.containerStackViewBottomLayoutConstraint.constant = 5 // 5pt margin when no status view } } + + static func configureStatusAccessibilityLabel(cell: NotificationStatusTableViewCell) { + // FIXME: + cell.accessibilityLabel = { + var accessibilityViews: [UIView?] = [] + accessibilityViews.append(contentsOf: [ + cell.titleLabel, + cell.timestampLabel, + cell.statusView + ]) + if !cell.statusContainerView.isHidden { + if !cell.statusView.headerContainerView.isHidden { + accessibilityViews.append(cell.statusView.headerInfoLabel) + } + accessibilityViews.append(contentsOf: [ + cell.statusView.nameMetaLabel, + cell.statusView.dateLabel, + cell.statusView.contentMetaText.textView, + ]) + } + return accessibilityViews + .compactMap { $0?.accessibilityLabel } + .joined(separator: " ") + }() + } } + diff --git a/Mastodon/Diffiable/Section/Status/PollSection.swift b/Mastodon/Diffiable/Section/Status/PollSection.swift index add2a79b..682a2abc 100644 --- a/Mastodon/Diffiable/Section/Status/PollSection.swift +++ b/Mastodon/Diffiable/Section/Status/PollSection.swift @@ -37,6 +37,15 @@ extension PollSection { managedObjectContext.performAndWait { let option = managedObjectContext.object(with: objectID) as! PollOption PollSection.configure(cell: cell, pollOption: option, pollItemAttribute: attribute) + + cell.isAccessibilityElement = true + cell.accessibilityLabel = { + var labels: [String] = [option.title] + if let percentage = cell.pollOptionView.optionPercentageLabel.text { + labels.append(percentage) + } + return labels.joined(separator: ",") + }() } return cell } diff --git a/Mastodon/Diffiable/Section/Status/StatusSection.swift b/Mastodon/Diffiable/Section/Status/StatusSection.swift index ceb0c945..61217c79 100644 --- a/Mastodon/Diffiable/Section/Status/StatusSection.swift +++ b/Mastodon/Diffiable/Section/Status/StatusSection.swift @@ -158,6 +158,11 @@ extension StatusSection { accessibilityElements.append(cell.statusView.avatarView) accessibilityElements.append(cell.statusView.nameMetaLabel) accessibilityElements.append(cell.statusView.dateLabel) + // poll + accessibilityElements.append(cell.statusView.pollTableView) + accessibilityElements.append(cell.statusView.pollVoteCountLabel) + accessibilityElements.append(cell.statusView.pollCountdownLabel) + accessibilityElements.append(cell.statusView.pollVoteButton) // TODO: a11y accessibilityElements.append(cell.statusView.contentMetaText.textView) accessibilityElements.append(contentsOf: cell.statusView.statusMosaicImageViewContainer.imageViews) @@ -389,7 +394,7 @@ extension StatusSection { // set timestamp let createdAt = (status.reblog ?? status).createdAt cell.statusView.dateLabel.text = createdAt.localizedSlowedTimeAgoSinceNow - cell.statusView.dateLabel.accessibilityValue = createdAt.timeAgoSinceNow + cell.statusView.dateLabel.accessibilityLabel = createdAt.timeAgoSinceNow AppContext.shared.timestampUpdatePublisher .receive(on: RunLoop.main) // will be paused when scrolling (on purpose) .sink { [weak cell] _ in @@ -978,6 +983,7 @@ extension StatusSection { cell.statusView.pollCountdownLabel.text = "-" } + cell.statusView.isUserInteractionEnabled = !poll.expired // make voice over touch passthroughable cell.statusView.pollTableView.allowsSelection = !poll.expired let votedOptions = poll.options.filter { option in