From 2c4d2ce551dba26801c2102554f4cd4dd2b0ed6e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 6 Jun 2021 21:50:45 -0400 Subject: [PATCH] Make polls in statuses accessible --- Tusker/Views/Poll/PollOptionView.swift | 9 ++++++++- Tusker/Views/Poll/PollOptionsView.swift | 2 ++ Tusker/Views/Poll/StatusPollView.swift | 6 ++---- .../Views/Status/BaseStatusTableViewCell.swift | 2 +- .../ConversationMainStatusTableViewCell.swift | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Tusker/Views/Poll/PollOptionView.swift b/Tusker/Views/Poll/PollOptionView.swift index d902244a..f9b8f2af 100644 --- a/Tusker/Views/Poll/PollOptionView.swift +++ b/Tusker/Views/Poll/PollOptionView.swift @@ -44,12 +44,15 @@ class PollOptionView: UIView { percentLabel.setContentHuggingPriority(.required, for: .horizontal) addSubview(percentLabel) + accessibilityLabel = option.title + if (poll.voted ?? false) || poll.effectiveExpired, let optionVotes = option.votesCount { let frac = poll.votesCount == 0 ? 0 : CGFloat(optionVotes) / CGFloat(poll.votesCount) + let percent = String(format: "%.0f%%", frac * 100) percentLabel.isHidden = false - percentLabel.text = String(format: "%.0f%%", frac * 100) + percentLabel.text = percent let fillView = UIView() fillView.translatesAutoresizingMaskIntoConstraints = false @@ -64,6 +67,8 @@ class PollOptionView: UIView { fillView.topAnchor.constraint(equalTo: topAnchor), fillView.bottomAnchor.constraint(equalTo: bottomAnchor), ]) + + accessibilityLabel! += ", \(percent)" } let minHeightConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: minHeight) @@ -86,6 +91,8 @@ class PollOptionView: UIView { percentLabel.bottomAnchor.constraint(equalTo: bottomAnchor), percentLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8), ]) + + isAccessibilityElement = true } required init?(coder: NSCoder) { diff --git a/Tusker/Views/Poll/PollOptionsView.swift b/Tusker/Views/Poll/PollOptionsView.swift index e979d12d..a8908ac5 100644 --- a/Tusker/Views/Poll/PollOptionsView.swift +++ b/Tusker/Views/Poll/PollOptionsView.swift @@ -69,6 +69,8 @@ class PollOptionsView: UIControl { stack.addArrangedSubview(optionView) return optionView } + + accessibilityElements = options } private func selectOption(_ option: PollOptionView) { diff --git a/Tusker/Views/Poll/StatusPollView.swift b/Tusker/Views/Poll/StatusPollView.swift index 99b87424..62a1a38e 100644 --- a/Tusker/Views/Poll/StatusPollView.swift +++ b/Tusker/Views/Poll/StatusPollView.swift @@ -28,7 +28,6 @@ class StatusPollView: UIView { private var optionsView: PollOptionsView! private var voteButton: UIButton! private var infoLabel: UILabel! - private var options: [PollOptionView] = [] private var canVote = true private var animator: UIViewPropertyAnimator! @@ -74,15 +73,14 @@ class StatusPollView: UIView { voteButton.topAnchor.constraint(equalTo: optionsView.bottomAnchor), voteButton.bottomAnchor.constraint(equalTo: bottomAnchor), ]) + + accessibilityElements = [optionsView!, infoLabel!, voteButton!] } func updateUI(status: StatusMO, poll: Poll?) { self.statusID = status.id self.poll = poll - // remove old options - options.forEach { $0.removeFromSuperview() } - guard let poll = poll else { return } // poll.voted is nil if there is no user (e.g., public timeline), in which case the poll also cannot be voted upon diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 70550d09..821fd9df 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -94,7 +94,7 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { collapseButton.layer.masksToBounds = true collapseButton.layer.cornerRadius = 5 - accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!] + accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!, pollView!] attachmentsView.isAccessibilityElement = true moreButton.showsMenuAsPrimaryAction = true diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift index 7aff9727..55cc48ce 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift @@ -33,7 +33,21 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell { profileAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self) profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self) - accessibilityElements = [profileAccessibilityElement!, contentWarningLabel!, collapseButton!, contentTextView!, totalFavoritesButton!, totalReblogsButton!, timestampAndClientLabel!, replyButton!, favoriteButton!, reblogButton!, moreButton!] + accessibilityElements = [ + profileAccessibilityElement!, + contentWarningLabel!, + collapseButton!, + contentTextView!, + attachmentsView!, + pollView!, + totalFavoritesButton!, + totalReblogsButton!, + timestampAndClientLabel!, + replyButton!, + favoriteButton!, + reblogButton!, + moreButton!, + ] contentTextView.defaultFont = .systemFont(ofSize: 18)