From 9c30ecd9c0065b5ba3f06f0ce14e3ff4d1148656 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Mon, 6 Feb 2023 21:29:39 -0500 Subject: [PATCH] Make the translation info view accessible at the root of a thread --- .../StatusThreadRootTableViewCell.swift | 1 + .../MastodonUI/View/Content/StatusView.swift | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift index 73b700e27..6de60c66b 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusThreadRootTableViewCell.swift @@ -108,6 +108,7 @@ extension StatusThreadRootTableViewCell { statusView.viewModel.isContentReveal ? statusView.contentMetaText.textView : statusView.spoilerOverlayView, + statusView.translatedInfoView, statusView.mediaGridContainerView, statusView.pollTableView, statusView.pollStatusStackView, diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index b2e5a49ae..e51ccfedf 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -197,8 +197,17 @@ public final class StatusView: UIView { label.numberOfLines = 0 return label }() - lazy var translatedInfoView: UIView = { - let containerView = UIView() + + private class TranslatedInfoView: UIView { + var revertAction: (() -> Void)? + + override func accessibilityActivate() -> Bool { + revertAction?() + return true + } + } + public private(set) lazy var translatedInfoView: UIView = { + let containerView = TranslatedInfoView() let revertButton = UIButton() revertButton.titleLabel?.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .bold)) @@ -230,7 +239,14 @@ public final class StatusView: UIView { ]) containerView.isHidden = true - + + containerView.isAccessibilityElement = true + containerView.accessibilityLabel = L10n.Common.Controls.Status.Translation.showOriginal + containerView.accessibilityTraits = [.button] + containerView.revertAction = { [weak self] in + self?.revertTranslation() + } + return containerView }() @@ -750,10 +766,12 @@ extension StatusView { .sink { [weak self] translatedFromLanguage, translatedUsingProvider in guard let self = self else { return } if let translatedFromLanguage = translatedFromLanguage { - self.translatedInfoLabel.text = L10n.Common.Controls.Status.Translation.translatedFrom( + let label = L10n.Common.Controls.Status.Translation.translatedFrom( Locale.current.localizedString(forIdentifier: translatedFromLanguage) ?? L10n.Common.Controls.Status.Translation.unknownLanguage, translatedUsingProvider ?? L10n.Common.Controls.Status.Translation.unknownProvider ) + self.translatedInfoLabel.text = label + self.translatedInfoView.accessibilityValue = label self.translatedInfoView.isHidden = false } else { self.translatedInfoView.isHidden = true