From 1808aaa3e8a08ca90d3a98c72ce5df1584a28372 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Sep 2019 20:53:22 -0400 Subject: [PATCH] A bunch of VoiceOver/Voice Control stuff --- .../Compose/ComposeViewController.swift | 12 +++++- .../Screens/Compose/ComposeViewController.xib | 24 ++++++----- Tusker/Screens/Compose/StatusFormat.swift | 13 ++++++ .../LargeAccountDetailView.swift | 1 + .../AttachmentsContainerView.swift | 43 +++++++++++++++---- .../ComposeStatusReplyView.xib | 13 +++--- .../ProfileHeaderTableViewCell.xib | 13 ++++-- .../ConversationMainStatusTableViewCell.swift | 31 ++++++++++++- .../ConversationMainStatusTableViewCell.xib | 27 +++++++++--- Tusker/Views/Status/StatusTableViewCell.swift | 33 ++++++++++++++ Tusker/Views/Status/StatusTableViewCell.xib | 36 +++++++++++++--- 11 files changed, 203 insertions(+), 43 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 6bdd9cfae5..5d7183bb1f 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -103,7 +103,9 @@ class ComposeViewController: UIViewController { let toolbar = UIToolbar() contentWarningBarButtonItem = UIBarButtonItem(title: "CW", style: .plain, target: self, action: #selector(contentWarningButtonPressed)) + contentWarningBarButtonItem.accessibilityLabel = NSLocalizedString("Add Content Warning", comment: "add CW accessibility label") visibilityBarButtonItem = UIBarButtonItem(image: UIImage(systemName: Preferences.shared.defaultPostVisibility.imageName), style: .plain, target: self, action: #selector(visibilityButtonPressed)) + visibilityBarButtonItem.accessibilityLabel = String(format: NSLocalizedString("Visibility: %s", comment: "compose visiblity accessibility label"), Preferences.shared.defaultPostVisibility.displayName) toolbar.items = [ contentWarningBarButtonItem, visibilityBarButtonItem, @@ -231,6 +233,7 @@ class ComposeViewController: UIViewController { fatalError("StatusFormat must have either an image or a title") } item.tag = StatusFormat.allCases.firstIndex(of: format)! + item.accessibilityLabel = format.accessibilityLabel return item } } @@ -266,7 +269,8 @@ class ComposeViewController: UIViewController { charactersRemainingLabel.textColor = .darkGray postBarButtonItem.isEnabled = true } - charactersRemainingLabel.text = remaining.description + charactersRemainingLabel.text = String(remaining) + charactersRemainingLabel.accessibilityLabel = String(format: NSLocalizedString("%d characters remaining", comment: "compose characters remaining accessibility label"), remaining) } func updateHasChanges() { @@ -309,10 +313,16 @@ class ComposeViewController: UIViewController { func contentWarningStateChanged() { contentWarningContainerView.isHidden = !contentWarningEnabled + if contentWarningEnabled { + contentWarningBarButtonItem.accessibilityLabel = NSLocalizedString("Remove Content Warning", comment: "remove CW accessibility label") + } else { + contentWarningBarButtonItem.accessibilityLabel = NSLocalizedString("Add Content Warning", comment: "add CW accessibility label") + } } func visibilityChanged() { visibilityBarButtonItem.image = UIImage(systemName: visibility.imageName) + visibilityBarButtonItem.accessibilityLabel = String(format: NSLocalizedString("Visibility: %s", comment: "compose visiblity accessibility label"), Preferences.shared.defaultPostVisibility.displayName) } func saveDraft() { diff --git a/Tusker/Screens/Compose/ComposeViewController.xib b/Tusker/Screens/Compose/ComposeViewController.xib index 412ffc2d5f..7142258a74 100644 --- a/Tusker/Screens/Compose/ComposeViewController.xib +++ b/Tusker/Screens/Compose/ComposeViewController.xib @@ -1,11 +1,10 @@ - + - + - @@ -44,11 +43,14 @@ + + + @@ -66,7 +68,7 @@ - + @@ -86,7 +88,7 @@ - + @@ -117,14 +119,14 @@ - + - + @@ -137,7 +139,7 @@ - + @@ -182,7 +184,7 @@ - + @@ -198,6 +200,6 @@ - + diff --git a/Tusker/Screens/Compose/StatusFormat.swift b/Tusker/Screens/Compose/StatusFormat.swift index 002a5fc5a9..a791b45933 100644 --- a/Tusker/Screens/Compose/StatusFormat.swift +++ b/Tusker/Screens/Compose/StatusFormat.swift @@ -45,6 +45,19 @@ enum StatusFormat: CaseIterable { return nil } } + + var accessibilityLabel: String { + switch self { + case .italics: + return NSLocalizedString("Italics", comment: "italics text format accessibility label") + case .bold: + return NSLocalizedString("Bold", comment: "bold text format accessibility label") + case .strikethrough: + return NSLocalizedString("Strikethrough", comment: "strikethrough text format accessibility label") + case .code: + return NSLocalizedString("Code", comment: "code text format accessibility label") + } + } } typealias FormatInsertionResult = (prefix: String, suffix: String, insertionPoint: Int) diff --git a/Tusker/Views/Account Detail/LargeAccountDetailView.swift b/Tusker/Views/Account Detail/LargeAccountDetailView.swift index 3b41785f6f..85084edc0b 100644 --- a/Tusker/Views/Account Detail/LargeAccountDetailView.swift +++ b/Tusker/Views/Account Detail/LargeAccountDetailView.swift @@ -29,6 +29,7 @@ class LargeAccountDetailView: UIView { usernameLabel.translatesAutoresizingMaskIntoConstraints = false usernameLabel.font = .systemFont(ofSize: 17, weight: .light) usernameLabel.textColor = .secondaryLabel + usernameLabel.isAccessibilityElement = false addSubview(usernameLabel) NSLayoutConstraint.activate([ diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 224f92de83..567559ad17 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -56,44 +56,57 @@ class AttachmentsContainerView: UIView { if attachments.count > 0 { self.isHidden = false + var accessibilityElements = [Any]() + switch attachments.count { case 1: - fillView(createAttachmentView(index: 0)) + let attachmentView = createAttachmentView(index: 0) + fillView(attachmentView) + accessibilityElements.append(attachmentView) case 2: let left = createAttachmentView(index: 0) + let right = createAttachmentView(index: 1) fillView(createAttachmentsStack(axis: .horizontal, arrangedSubviews: [ left, - createAttachmentView(index: 1) + right ])) NSLayoutConstraint.activate([ left.halfWidth() ]) + accessibilityElements.append(left) + accessibilityElements.append(right) case 3: let left = createAttachmentView(index: 0) let topRight = createAttachmentView(index: 1) + let bottomRight = createAttachmentView(index: 2) fillView(createAttachmentsStack(axis: .horizontal, arrangedSubviews: [ left, createAttachmentsStack(axis: .vertical, arrangedSubviews: [ topRight, - createAttachmentView(index: 2) + bottomRight ]) ])) NSLayoutConstraint.activate([ left.halfWidth(), topRight.halfHeight(), ]) + accessibilityElements.append(left) + accessibilityElements.append(topRight) + accessibilityElements.append(bottomRight) case 4: let topLeft = createAttachmentView(index: 0) + let bottomLeft = createAttachmentView(index: 2) let left = createAttachmentsStack(axis: .vertical, arrangedSubviews: [ topLeft, - createAttachmentView(index: 2) + bottomLeft ]) let topRight = createAttachmentView(index: 1) + let bottomRight = createAttachmentView(index: 3) fillView(createAttachmentsStack(axis: .horizontal, arrangedSubviews: [ left, createAttachmentsStack(axis: .vertical, arrangedSubviews: [ topRight, - createAttachmentView(index: 3) + bottomRight ]) ])) NSLayoutConstraint.activate([ @@ -101,6 +114,10 @@ class AttachmentsContainerView: UIView { topLeft.halfHeight(), topRight.halfHeight(), ]) + accessibilityElements.append(topLeft) + accessibilityElements.append(topRight) + accessibilityElements.append(bottomLeft) + accessibilityElements.append(bottomRight) default: // more than 4 let moreView = UIView() moreView.backgroundColor = .secondarySystemBackground @@ -112,12 +129,13 @@ class AttachmentsContainerView: UIView { moreLabel.textColor = .secondaryLabel moreLabel.textAlignment = .center moreLabel.translatesAutoresizingMaskIntoConstraints = false - moreView.addSubview(moreLabel) + moreView.accessibilityLabel = moreLabel.text let topLeft = createAttachmentView(index: 0) + let bottomLeft = createAttachmentView(index: 2) let left = createAttachmentsStack(axis: .vertical, arrangedSubviews: [ topLeft, - createAttachmentView(index: 2) + bottomLeft ]) let topRight = createAttachmentView(index: 1) fillView(createAttachmentsStack(axis: .horizontal, arrangedSubviews: [ @@ -136,11 +154,17 @@ class AttachmentsContainerView: UIView { moreView.topAnchor.constraint(equalTo: moreLabel.topAnchor), moreLabel.bottomAnchor.constraint(equalTo: moreView.bottomAnchor), ]) + accessibilityElements.append(topLeft) + accessibilityElements.append(topRight) + accessibilityElements.append(bottomLeft) + accessibilityElements.append(moreView) } + + self.accessibilityElements = accessibilityElements } else { self.isHidden = true } - + if status.sensitive { contentHidden = true createBlurView() @@ -152,6 +176,9 @@ class AttachmentsContainerView: UIView { let attachmentView = AttachmentView(attachment: attachments[index], index: index) attachmentView.delegate = delegate attachmentView.translatesAutoresizingMaskIntoConstraints = false + attachmentView.isAccessibilityElement = true + attachmentView.accessibilityTraits = [.image, .button] + attachmentView.accessibilityLabel = String(format: NSLocalizedString("Attachment %d", comment: "attachment at index accessiblity label"), index + 1) attachmentViews.add(attachmentView) return attachmentView } diff --git a/Tusker/Views/Compose Status Reply/ComposeStatusReplyView.xib b/Tusker/Views/Compose Status Reply/ComposeStatusReplyView.xib index d97672a537..43fe156ca2 100644 --- a/Tusker/Views/Compose Status Reply/ComposeStatusReplyView.xib +++ b/Tusker/Views/Compose Status Reply/ComposeStatusReplyView.xib @@ -1,11 +1,10 @@ - + - + - @@ -32,8 +31,12 @@