Make the translation info view accessible at the root of a thread

This commit is contained in:
Jed Fox 2023-02-06 21:29:39 -05:00
parent 3b87916d9a
commit 9c30ecd9c0
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
2 changed files with 23 additions and 4 deletions

View File

@ -108,6 +108,7 @@ extension StatusThreadRootTableViewCell {
statusView.viewModel.isContentReveal
? statusView.contentMetaText.textView
: statusView.spoilerOverlayView,
statusView.translatedInfoView,
statusView.mediaGridContainerView,
statusView.pollTableView,
statusView.pollStatusStackView,

View File

@ -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