DragIndicatorView now handles a11y itself

…and also gains the button trait
…also the escape gesture now works!
This commit is contained in:
Jed Fox 2022-11-06 20:01:30 -05:00
parent 95481f1d6d
commit fe98dfe4ca
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
2 changed files with 19 additions and 16 deletions

View File

@ -34,7 +34,9 @@ final class AccountListViewController: UIViewController, NeedsDependency {
return barButtonItem
}()
let dragIndicatorView = DragIndicatorView()
lazy var dragIndicatorView = DragIndicatorView { [weak self] in
self?.dismiss(animated: true, completion: nil)
}
var hasLoaded = false
private(set) lazy var tableView: UITableView = {
@ -130,14 +132,6 @@ extension AccountListViewController {
self.panModalTransition(to: .shortForm)
}
.store(in: &disposeBag)
if UIAccessibility.isVoiceOverRunning {
let dragIndicatorTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
dragIndicatorView.addGestureRecognizer(dragIndicatorTapGestureRecognizer)
dragIndicatorTapGestureRecognizer.addTarget(self, action: #selector(AccountListViewController.dragIndicatorTapGestureRecognizerHandler(_:)))
dragIndicatorView.isAccessibilityElement = true
dragIndicatorView.accessibilityLabel = L10n.Scene.AccountList.dismissAccountSwitcher
}
}
private func setupBackgroundColor(theme: Theme) {
@ -161,9 +155,10 @@ extension AccountListViewController {
_ = coordinator.present(scene: .welcome, from: self, transition: .modal(animated: true, completion: nil))
}
@objc private func dragIndicatorTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
override func accessibilityPerformEscape() -> Bool {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
dismiss(animated: true, completion: nil)
return true
}
}

View File

@ -15,17 +15,17 @@ final class DragIndicatorView: UIView {
let barView = UIView()
let separatorLine = UIView.separatorLine
let onDismiss: () -> Void
override init(frame: CGRect) {
super.init(frame: frame)
init(onDismiss: @escaping () -> Void) {
self.onDismiss = onDismiss
super.init(frame: .zero)
_init()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
fatalError("init(coder:) is not supported")
}
}
extension DragIndicatorView {
@ -52,6 +52,14 @@ extension DragIndicatorView {
separatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)),
])
isAccessibilityElement = true
accessibilityTraits = .button
accessibilityLabel = L10n.Scene.AccountList.dismissAccountSwitcher
}
override func accessibilityActivate() -> Bool {
self.onDismiss()
return true
}
}