From 45517c0df69c111b38fec0fe16534057a63c99b6 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Tue, 2 Feb 2021 13:49:29 -0800 Subject: [PATCH] VoiceOver wip --- Localizations/Localizable.strings | 2 + Views/UIKit/Content Views/AccountView.swift | 54 ++++++++++++++++--- .../AccountTableViewCell.swift | 1 + 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index dc719cc..a55c8a5 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -3,6 +3,7 @@ "about" = "About"; "about.acknowledgments" = "Acknowledgments"; "account.%@-followers" = "%@'s Followers"; +"account.accept-follow-request-button.accessibility-label" = "Accept follow request"; "account.avatar.accessibility-label-%@" = "Avatar: %@"; "account.block" = "Block"; "account.block.confirm-%@" = "Block %@?"; @@ -19,6 +20,7 @@ "account.header.accessibility-label-%@" = "Header image: %@"; "account.hide-reblogs" = "Hide boosts"; "account.mute" = "Mute"; +"account.reject-follow-request-button.accessibility-label" = "Reject follow request"; "account.request" = "Request"; "account.statuses.post" = "Posts"; "account.statuses.toot" = "Toots"; diff --git a/Views/UIKit/Content Views/AccountView.swift b/Views/UIKit/Content Views/AccountView.swift index 61d52c6..acc1dd5 100644 --- a/Views/UIKit/Content Views/AccountView.swift +++ b/Views/UIKit/Content Views/AccountView.swift @@ -147,22 +147,23 @@ private extension AccountView { stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor), stackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor) ]) + + isAccessibilityElement = true } + // swiftlint:disable:next function_body_length func applyAccountConfiguration() { let viewModel = accountConfiguration.viewModel avatarImageView.kf.setImage(with: viewModel.avatarURL(profile: false)) - if viewModel.displayName.isEmpty { - displayNameLabel.isHidden = true - } else { - let mutableDisplayName = NSMutableAttributedString(string: viewModel.displayName) + let mutableDisplayName = NSMutableAttributedString(string: viewModel.displayName) - mutableDisplayName.insert(emojis: viewModel.emojis, view: displayNameLabel) - mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight) - displayNameLabel.attributedText = mutableDisplayName - } + mutableDisplayName.insert(emojis: viewModel.emojis, view: displayNameLabel) + mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight) + displayNameLabel.attributedText = mutableDisplayName + + displayNameLabel.isHidden = viewModel.displayName.isEmpty accountLabel.text = viewModel.accountName @@ -189,5 +190,42 @@ private extension AccountView { acceptFollowRequestButton.isHidden = !isFollowRequest rejectFollowRequestButton.isHidden = !isFollowRequest + + let accessibilityAttributedLabel = NSMutableAttributedString(string: "") + + if !displayNameLabel.isHidden, let displayName = displayNameLabel.attributedText { + accessibilityAttributedLabel.append(displayName) + accessibilityAttributedLabel.appendWithSeparator(viewModel.accountName) + } else { + accessibilityAttributedLabel.appendWithSeparator(viewModel.accountName) + } + + if !noteTextView.isHidden, let note = noteTextView.attributedText { + accessibilityAttributedLabel.appendWithSeparator(note) + } + + self.accessibilityAttributedLabel = accessibilityAttributedLabel + + if isFollowRequest { + accessibilityCustomActions = [ + UIAccessibilityCustomAction( + name: NSLocalizedString( + "account.accept-follow-request-button.accessibility-label", + comment: "")) { [weak self] _ in + self?.accountConfiguration.viewModel.acceptFollowRequest() + + return true + }, + UIAccessibilityCustomAction( + name: NSLocalizedString( + "account.reject-follow-request-button.accessibility-label", + comment: "")) { [weak self] _ in + self?.accountConfiguration.viewModel.rejectFollowRequest() + + return true + }] + } else { + accessibilityCustomActions = [] + } } } diff --git a/Views/UIKit/Table View Cells/AccountTableViewCell.swift b/Views/UIKit/Table View Cells/AccountTableViewCell.swift index 5ca62e1..0eec342 100644 --- a/Views/UIKit/Table View Cells/AccountTableViewCell.swift +++ b/Views/UIKit/Table View Cells/AccountTableViewCell.swift @@ -10,6 +10,7 @@ final class AccountTableViewCell: UITableViewCell { guard let viewModel = viewModel else { return } contentConfiguration = AccountContentConfiguration(viewModel: viewModel).updated(for: state) + accessibilityElements = [contentView] } override func layoutSubviews() {