From fccd4e427c302f4382385c8b36fadbcbc1aff586 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 21 Jul 2024 14:03:18 -0700 Subject: [PATCH] Fix profile moved header not being VO accessible Closes #479 --- .../ProfileHeaderMovedOverlayView.swift | 44 ++++++++++++++++++- .../Profile Header/ProfileHeaderView.swift | 10 ++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Tusker/Views/Profile Header/ProfileHeaderMovedOverlayView.swift b/Tusker/Views/Profile Header/ProfileHeaderMovedOverlayView.swift index 696b36e2..f061bc0c 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderMovedOverlayView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderMovedOverlayView.swift @@ -14,7 +14,8 @@ class ProfileHeaderMovedOverlayView: UIView { weak var delegate: TuskerNavigationDelegate? var collapse: (() -> Void)? - + var hide: (() -> Void)? + private var avatarImageView: CachedImageView! private var displayNameLabel: EmojiLabel! private var usernameLabel: UILabel! @@ -144,7 +145,46 @@ class ProfileHeaderMovedOverlayView: UIView { @objc private func accountTapped() { delegate?.selected(account: movedToID) } - + + // MARK: Accessibility + + override var isAccessibilityElement: Bool { + get { true } + set {} + } + + override var accessibilityLabel: String? { + get { + guard let movedToID, + let account = delegate?.apiController?.persistentContainer.account(for: movedToID) else { + return "This account has moved" + } + return "This account has moved to @\(account.acct)" + } + set {} + } + + override func accessibilityActivate() -> Bool { + guard let movedToID, + let delegate else { + return false + } + delegate.selected(account: movedToID) + return true + } + + override var accessibilityCustomActions: [UIAccessibilityCustomAction]? { + get { + [ + UIAccessibilityCustomAction(name: "Hide banner", actionHandler: { [unowned self] _ in + self.hide?() + return true + }) + ] + } + set {} + } + } extension ProfileHeaderMovedOverlayView: UIPointerInteractionDelegate { diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index 2bc13026..6e4ee2df 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -41,6 +41,7 @@ class ProfileHeaderView: UIView { @IBOutlet weak var followersCountButton: UIButton! private(set) var pagesSegmentedControl: ScrollingSegmentedControl! private var movedOverlayView: ProfileHeaderMovedOverlayView? + private var hideMovedOverlayView = false var accountID: String! @@ -178,7 +179,8 @@ class ProfileHeaderView: UIView { followersCountButton.setAttributedTitle(followersCountTitle, for: .normal) followersCountButton.accessibilityLabel = "\(followersSpelledOut) followers" - if let movedTo = account.movedTo { + if let movedTo = account.movedTo, + !hideMovedOverlayView { if let movedOverlayView { movedOverlayView.updateUI(movedTo: movedTo) } else { @@ -235,6 +237,12 @@ class ProfileHeaderView: UIView { } animator.startAnimation() } + overlay.hide = { [weak self] in + guard let self else { return } + self.hideMovedOverlayView = true + self.updateUI(for: self.accountID) + UIAccessibility.post(notification: .layoutChanged, argument: self) + } return overlay }