Make polls in statuses accessible
This commit is contained in:
parent
bbe260bc9e
commit
2c4d2ce551
|
@ -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) {
|
||||
|
|
|
@ -69,6 +69,8 @@ class PollOptionsView: UIControl {
|
|||
stack.addArrangedSubview(optionView)
|
||||
return optionView
|
||||
}
|
||||
|
||||
accessibilityElements = options
|
||||
}
|
||||
|
||||
private func selectOption(_ option: PollOptionView) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue