From fe98dfe4cae898558e5cc007457333170b09c69a Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 6 Nov 2022 20:01:30 -0500 Subject: [PATCH 1/9] DragIndicatorView now handles a11y itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and also gains the button trait …also the escape gesture now works! --- .../Scene/Account/AccountViewController.swift | 17 ++++++----------- .../Scene/Account/View/DragIndicatorView.swift | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Mastodon/Scene/Account/AccountViewController.swift b/Mastodon/Scene/Account/AccountViewController.swift index e25c75b01..7a0e529cc 100644 --- a/Mastodon/Scene/Account/AccountViewController.swift +++ b/Mastodon/Scene/Account/AccountViewController.swift @@ -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) { @@ -160,10 +154,11 @@ extension AccountListViewController { logger.debug("\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)") _ = 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 } } diff --git a/Mastodon/Scene/Account/View/DragIndicatorView.swift b/Mastodon/Scene/Account/View/DragIndicatorView.swift index 9e0ab77d5..a04d9cd8c 100644 --- a/Mastodon/Scene/Account/View/DragIndicatorView.swift +++ b/Mastodon/Scene/Account/View/DragIndicatorView.swift @@ -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 + } } From 547129ec95a04cf1c5d75ba1bdfab594a8d22208 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 6 Nov 2022 20:09:55 -0500 Subject: [PATCH 2/9] Hide the avatars in the account list from VO --- Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift index 66f49efe8..f0673293a 100644 --- a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift +++ b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift @@ -69,6 +69,7 @@ extension AccountListTableViewCell { ]) avatarButton.setContentHuggingPriority(.defaultLow, for: .horizontal) avatarButton.setContentHuggingPriority(.defaultLow, for: .vertical) + avatarButton.isAccessibilityElement = false let labelContainerStackView = UIStackView() labelContainerStackView.axis = .vertical From 6c6508cdfb9920fbfeca1ec84216b12421d62795 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 6 Nov 2022 20:10:10 -0500 Subject: [PATCH 3/9] Mark account list rows as buttons --- Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift | 2 ++ Mastodon/Scene/Account/Cell/AddAccountTableViewCell.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift index f0673293a..cd214f2c7 100644 --- a/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift +++ b/Mastodon/Scene/Account/Cell/AccountListTableViewCell.swift @@ -125,6 +125,8 @@ extension AccountListTableViewCell { badgeButton.setBadge(number: 0) checkmarkImageView.isHidden = true + + accessibilityTraits.insert(.button) } } diff --git a/Mastodon/Scene/Account/Cell/AddAccountTableViewCell.swift b/Mastodon/Scene/Account/Cell/AddAccountTableViewCell.swift index 3ff3066a2..bc47aef43 100644 --- a/Mastodon/Scene/Account/Cell/AddAccountTableViewCell.swift +++ b/Mastodon/Scene/Account/Cell/AddAccountTableViewCell.swift @@ -108,6 +108,8 @@ extension AddAccountTableViewCell { separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)), ]) + + accessibilityTraits.insert(.button) } } From c3d7357456af98a54e642042bb8d7da1be96db00 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 6 Nov 2022 20:14:52 -0500 Subject: [PATCH 4/9] Try to fix strings for a11y.plural.count.unread.notification --- Localization/Localizable.stringsdict | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Localization/Localizable.stringsdict b/Localization/Localizable.stringsdict index 051bb50ef..93d566f70 100644 --- a/Localization/Localizable.stringsdict +++ b/Localization/Localizable.stringsdict @@ -13,15 +13,15 @@ NSStringFormatValueTypeKey ld zero - no unread notification + no unread notifications one 1 unread notification few %ld unread notifications many - %ld unread notification + %ld unread notifications other - %ld unread notification + %ld unread notifications a11y.plural.count.input_limit_exceeds From fd31e08089141493094ae7f00790fc144a086f5f Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sun, 6 Nov 2022 20:15:09 -0500 Subject: [PATCH 5/9] Clarify separation between name/username/badge --- Mastodon/Scene/Account/AccountListViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mastodon/Scene/Account/AccountListViewModel.swift b/Mastodon/Scene/Account/AccountListViewModel.swift index e0aaf97fc..75797fd47 100644 --- a/Mastodon/Scene/Account/AccountListViewModel.swift +++ b/Mastodon/Scene/Account/AccountListViewModel.swift @@ -166,7 +166,7 @@ extension AccountListViewModel { cell.badgeButton.accessibilityLabel ] .compactMap { $0 } - .joined(separator: " ") + .joined(separator: ", ") } } From f9daeea4d3ad66a5387493b67682c4e27396d2bf Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Mon, 7 Nov 2022 13:32:15 -0500 Subject: [PATCH 6/9] =?UTF-8?q?Add=20a=20custom=20action=20for=20=E2=80=9C?= =?UTF-8?q?switch=20accounts=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Localization/app.json | 6 ++-- .../Root/ContentSplitViewController.swift | 1 + .../Root/MainTab/MainTabBarController.swift | 30 ++++++++++++------- .../Root/Sidebar/SidebarViewController.swift | 13 ++++++++ .../Scene/Root/Sidebar/SidebarViewModel.swift | 21 +++++++++++-- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/Localization/app.json b/Localization/app.json index a965b23ae..47d0e63a5 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -676,9 +676,9 @@ } }, "account_list": { - "tab_bar_hint": "Current selected profile: %s. Double tap then hold to show account switcher", "dismiss_account_switcher": "Dismiss Account Switcher", - "add_account": "Add Account" + "add_account": "Add Account", + "switch_accounts": "Switch Accounts" }, "wizard": { "new_in_mastodon": "New in Mastodon", @@ -686,4 +686,4 @@ "accessibility_hint": "Double tap to dismiss this wizard" } } -} \ No newline at end of file +} diff --git a/Mastodon/Scene/Root/ContentSplitViewController.swift b/Mastodon/Scene/Root/ContentSplitViewController.swift index 3f4758e8e..4ae7204ca 100644 --- a/Mastodon/Scene/Root/ContentSplitViewController.swift +++ b/Mastodon/Scene/Root/ContentSplitViewController.swift @@ -33,6 +33,7 @@ final class ContentSplitViewController: UIViewController, NeedsDependency { sidebarViewController.context = context sidebarViewController.coordinator = coordinator sidebarViewController.viewModel = SidebarViewModel(context: context, authContext: authContext) + sidebarViewController.viewModel.delegate = sidebarViewController sidebarViewController.delegate = self return sidebarViewController }() diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index c49dcc1a1..d56a18aed 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -298,6 +298,7 @@ extension MainTabBarController { } .store(in: &disposeBag) + let profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag } if let user = authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.user { self.avatarURLObserver = user.publisher(for: \.avatar) .sink { [weak self, weak user] _ in @@ -306,15 +307,20 @@ extension MainTabBarController { guard user.managedObjectContext != nil else { return } self.avatarURL = user.avatarImageURL() } - - // a11y - let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag } - guard let profileTabItem = _profileTabItem else { return } - let currentUserDisplayName = user.displayNameWithFallback ?? "no user" - profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName) - + if let profileTabItem { + profileTabItem.accessibilityCustomActions = [ + // TODO: i18n (scene.account_list.switch_accounts) + UIAccessibilityCustomAction(name: "Switch Accounts") { [weak self] _ in + self?.showAccountSwitcher() + return true + } + ] + } } else { self.avatarURLObserver = nil + if let profileTabItem { + profileTabItem.accessibilityCustomActions = [] + } } let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer() @@ -390,13 +396,17 @@ extension MainTabBarController { switch tab { case .me: - guard let authContext = self.authContext else { return } - let accountListViewModel = AccountListViewModel(context: context, authContext: authContext) - _ = coordinator.present(scene: .accountList(viewModel: accountListViewModel), from: self, transition: .panModal) + showAccountSwitcher() default: break } } + + private func showAccountSwitcher() { + guard let authContext = self.authContext else { return } + let accountListViewModel = AccountListViewModel(context: context, authContext: authContext) + _ = coordinator.present(scene: .accountList(viewModel: accountListViewModel), from: self, transition: .panModal) + } } extension MainTabBarController { diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift index 70e1239b6..28e205047 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift @@ -162,6 +162,19 @@ extension SidebarViewController { } +extension SidebarViewController: SidebarViewModelDelegate { + func sidebarViewModelDidSwitchAccounts(_ sidebarViewModel: SidebarViewModel) { + guard let diffableDataSource = viewModel.diffableDataSource else { return } + guard let indexPath = diffableDataSource.indexPath(for: .tab(.me)) else { return } + guard let cell = collectionView.cellForItem(at: indexPath) else { return } + delegate?.sidebarViewController( + self, + didLongPressItem: .tab(.me), + sourceView: cell + ) + } +} + extension SidebarViewController { @objc private func sidebarLongPressGestureRecognizerHandler(_ sender: UILongPressGestureRecognizer) { guard sender.state == .began else { return } diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 9f0eb1899..22be9e6e0 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -15,6 +15,10 @@ import MastodonAsset import MastodonCore import MastodonLocalization +protocol SidebarViewModelDelegate: AnyObject { + func sidebarViewModelDidSwitchAccounts(_ sidebarViewModel: SidebarViewModel) +} + final class SidebarViewModel { var disposeBag = Set() @@ -31,6 +35,8 @@ final class SidebarViewModel { var secondaryDiffableDataSource: UICollectionViewDiffableDataSource? @Published private(set) var isReadyForWizardAvatarButton = false + weak var delegate: SidebarViewModelDelegate? + init(context: AppContext, authContext: AuthContext?) { self.context = context self.authContext = authContext @@ -127,9 +133,18 @@ extension SidebarViewModel { } .store(in: &cell.disposeBag) case .me: - guard let user = self.authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.user else { return } - let currentUserDisplayName = user.displayNameWithFallback - cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName) + if self.authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.user != nil { + cell.accessibilityCustomActions = [ + // TODO: i18n (scene.account_list.switch_accounts) + UIAccessibilityCustomAction(name: "Switch Accounts") { [weak self] _ in + guard let self, let delegate = self.delegate else { return false } + delegate.sidebarViewModelDidSwitchAccounts(self) + return true + } + ] + } else { + cell.accessibilityCustomActions = [] + } default: break } From b2d26078c10aaf9780e0ce05b3fa868c229e1ed2 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 8 Nov 2022 13:37:11 -0500 Subject: [PATCH 7/9] Update localization --- Localization/StringsConvertor/input/en.lproj/app.json | 4 ++-- Mastodon/Scene/Root/MainTab/MainTabBarController.swift | 3 +-- Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift | 3 +-- .../Sources/MastodonLocalization/Generated/Strings.swift | 6 ++---- .../Resources/en.lproj/Localizable.strings | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Localization/StringsConvertor/input/en.lproj/app.json b/Localization/StringsConvertor/input/en.lproj/app.json index a965b23ae..21c8ab481 100644 --- a/Localization/StringsConvertor/input/en.lproj/app.json +++ b/Localization/StringsConvertor/input/en.lproj/app.json @@ -676,9 +676,9 @@ } }, "account_list": { - "tab_bar_hint": "Current selected profile: %s. Double tap then hold to show account switcher", "dismiss_account_switcher": "Dismiss Account Switcher", - "add_account": "Add Account" + "add_account": "Add Account", + "switch_accounts": "Switch Accounts" }, "wizard": { "new_in_mastodon": "New in Mastodon", diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index d56a18aed..0eea7288e 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -309,8 +309,7 @@ extension MainTabBarController { } if let profileTabItem { profileTabItem.accessibilityCustomActions = [ - // TODO: i18n (scene.account_list.switch_accounts) - UIAccessibilityCustomAction(name: "Switch Accounts") { [weak self] _ in + UIAccessibilityCustomAction(name: L10n.Scene.AccountList.switchAccounts) { [weak self] _ in self?.showAccountSwitcher() return true } diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 97284e7b8..2a8082e47 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -136,8 +136,7 @@ extension SidebarViewModel { case .me: if self.authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.user != nil { cell.accessibilityCustomActions = [ - // TODO: i18n (scene.account_list.switch_accounts) - UIAccessibilityCustomAction(name: "Switch Accounts") { [weak self] _ in + UIAccessibilityCustomAction(name: L10n.Scene.AccountList.switchAccounts) { [weak self] _ in guard let self, let delegate = self.delegate else { return false } delegate.sidebarViewModelDidSwitchAccounts(self) return true diff --git a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift index 52ed59c09..00c3747d7 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift +++ b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift @@ -406,10 +406,8 @@ public enum L10n { public static let addAccount = L10n.tr("Localizable", "Scene.AccountList.AddAccount") /// Dismiss Account Switcher public static let dismissAccountSwitcher = L10n.tr("Localizable", "Scene.AccountList.DismissAccountSwitcher") - /// Current selected profile: %@. Double tap then hold to show account switcher - public static func tabBarHint(_ p1: Any) -> String { - return L10n.tr("Localizable", "Scene.AccountList.TabBarHint", String(describing: p1)) - } + /// Switch Accounts + public static let switchAccounts = L10n.tr("Localizable", "Scene.AccountList.SwitchAccounts") } public enum Bookmark { /// Your Bookmarks diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings index 6917eb0c7..f54ea8442 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings @@ -153,7 +153,7 @@ Your profile looks like this to them."; "Common.Controls.Timeline.Timestamp.Now" = "Now"; "Scene.AccountList.AddAccount" = "Add Account"; "Scene.AccountList.DismissAccountSwitcher" = "Dismiss Account Switcher"; -"Scene.AccountList.TabBarHint" = "Current selected profile: %@. Double tap then hold to show account switcher"; +"Scene.AccountList.SwitchAccounts" = "Switch Accounts"; "Scene.Bookmark.Title" = "Your Bookmarks"; "Scene.Compose.Accessibility.AppendAttachment" = "Add Attachment"; "Scene.Compose.Accessibility.AppendPoll" = "Add Poll"; From 120065104ccbf0d4516af618adcab97e3f432759 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Mon, 14 Nov 2022 08:45:10 -0500 Subject: [PATCH 8/9] =?UTF-8?q?Revert=20=E2=80=9CAdd=20a=20custom=20action?= =?UTF-8?q?=20for=20=E2=80=98switch=20accounts=E2=80=99=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f9daeea4d3ad66a5387493b67682c4e27396d2bf --- Localization/app.json | 6 ++--- .../Root/ContentSplitViewController.swift | 1 - .../Root/MainTab/MainTabBarController.swift | 27 ++++++------------- .../Root/Sidebar/SidebarViewController.swift | 13 --------- .../Scene/Root/Sidebar/SidebarViewModel.swift | 20 +++----------- 5 files changed, 14 insertions(+), 53 deletions(-) diff --git a/Localization/app.json b/Localization/app.json index 4c64d28f3..8fb7933c4 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -686,9 +686,9 @@ } }, "account_list": { + "tab_bar_hint": "Current selected profile: %s. Double tap then hold to show account switcher", "dismiss_account_switcher": "Dismiss Account Switcher", - "add_account": "Add Account", - "switch_accounts": "Switch Accounts" + "add_account": "Add Account" }, "wizard": { "new_in_mastodon": "New in Mastodon", @@ -699,4 +699,4 @@ "title": "Bookmarks" } } -} +} \ No newline at end of file diff --git a/Mastodon/Scene/Root/ContentSplitViewController.swift b/Mastodon/Scene/Root/ContentSplitViewController.swift index 4ae7204ca..3f4758e8e 100644 --- a/Mastodon/Scene/Root/ContentSplitViewController.swift +++ b/Mastodon/Scene/Root/ContentSplitViewController.swift @@ -33,7 +33,6 @@ final class ContentSplitViewController: UIViewController, NeedsDependency { sidebarViewController.context = context sidebarViewController.coordinator = coordinator sidebarViewController.viewModel = SidebarViewModel(context: context, authContext: authContext) - sidebarViewController.viewModel.delegate = sidebarViewController sidebarViewController.delegate = self return sidebarViewController }() diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index 0eea7288e..e2510071e 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -298,7 +298,6 @@ extension MainTabBarController { } .store(in: &disposeBag) - let profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag } if let user = authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.user { self.avatarURLObserver = user.publisher(for: \.avatar) .sink { [weak self, weak user] _ in @@ -307,19 +306,13 @@ extension MainTabBarController { guard user.managedObjectContext != nil else { return } self.avatarURL = user.avatarImageURL() } - if let profileTabItem { - profileTabItem.accessibilityCustomActions = [ - UIAccessibilityCustomAction(name: L10n.Scene.AccountList.switchAccounts) { [weak self] _ in - self?.showAccountSwitcher() - return true - } - ] - } + + // a11y + let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag } + guard let profileTabItem = _profileTabItem else { return } + profileTabItem.accessibilityHint = L10n.Scene.AccountList.tabBarHint(user.displayNameWithFallback) } else { self.avatarURLObserver = nil - if let profileTabItem { - profileTabItem.accessibilityCustomActions = [] - } } let tabBarLongPressGestureRecognizer = UILongPressGestureRecognizer() @@ -395,17 +388,13 @@ extension MainTabBarController { switch tab { case .me: - showAccountSwitcher() + guard let authContext = self.authContext else { return } + let accountListViewModel = AccountListViewModel(context: context, authContext: authContext) + _ = coordinator.present(scene: .accountList(viewModel: accountListViewModel), from: self, transition: .panModal) default: break } } - - private func showAccountSwitcher() { - guard let authContext = self.authContext else { return } - let accountListViewModel = AccountListViewModel(context: context, authContext: authContext) - _ = coordinator.present(scene: .accountList(viewModel: accountListViewModel), from: self, transition: .panModal) - } } extension MainTabBarController { diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift index 28e205047..70e1239b6 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewController.swift @@ -162,19 +162,6 @@ extension SidebarViewController { } -extension SidebarViewController: SidebarViewModelDelegate { - func sidebarViewModelDidSwitchAccounts(_ sidebarViewModel: SidebarViewModel) { - guard let diffableDataSource = viewModel.diffableDataSource else { return } - guard let indexPath = diffableDataSource.indexPath(for: .tab(.me)) else { return } - guard let cell = collectionView.cellForItem(at: indexPath) else { return } - delegate?.sidebarViewController( - self, - didLongPressItem: .tab(.me), - sourceView: cell - ) - } -} - extension SidebarViewController { @objc private func sidebarLongPressGestureRecognizerHandler(_ sender: UILongPressGestureRecognizer) { guard sender.state == .began else { return } diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 2a8082e47..c3f9e3e36 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -15,10 +15,6 @@ import MastodonAsset import MastodonCore import MastodonLocalization -protocol SidebarViewModelDelegate: AnyObject { - func sidebarViewModelDidSwitchAccounts(_ sidebarViewModel: SidebarViewModel) -} - final class SidebarViewModel { var disposeBag = Set() @@ -35,8 +31,6 @@ final class SidebarViewModel { var secondaryDiffableDataSource: UICollectionViewDiffableDataSource? @Published private(set) var isReadyForWizardAvatarButton = false - weak var delegate: SidebarViewModelDelegate? - init(context: AppContext, authContext: AuthContext?) { self.context = context self.authContext = authContext @@ -134,17 +128,9 @@ extension SidebarViewModel { } .store(in: &cell.disposeBag) case .me: - if self.authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.user != nil { - cell.accessibilityCustomActions = [ - UIAccessibilityCustomAction(name: L10n.Scene.AccountList.switchAccounts) { [weak self] _ in - guard let self, let delegate = self.delegate else { return false } - delegate.sidebarViewModelDidSwitchAccounts(self) - return true - } - ] - } else { - cell.accessibilityCustomActions = [] - } + guard let user = self.authContext?.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.user else { return } + let currentUserDisplayName = user.displayNameWithFallback + cell.accessibilityHint = L10n.Scene.AccountList.tabBarHint(currentUserDisplayName) default: break } From 6ec16d5a8115aaa5ff3c7d319d623db594e3d5e0 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 15 Nov 2022 07:00:15 -0500 Subject: [PATCH 9/9] Adjustments for new i18n workflow --- Localization/StringsConvertor/input/en.lproj/app.json | 4 ++-- .../Resources/en.lproj/Localizable.strings | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Localization/StringsConvertor/input/en.lproj/app.json b/Localization/StringsConvertor/input/en.lproj/app.json index 2b8745ecc..25f06ad83 100644 --- a/Localization/StringsConvertor/input/en.lproj/app.json +++ b/Localization/StringsConvertor/input/en.lproj/app.json @@ -698,9 +698,9 @@ } }, "account_list": { + "tab_bar_hint": "Current selected profile: %s. Double tap then hold to show account switcher", "dismiss_account_switcher": "Dismiss Account Switcher", - "add_account": "Add Account", - "switch_accounts": "Switch Accounts" + "add_account": "Add Account" }, "wizard": { "new_in_mastodon": "New in Mastodon", diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings index 66394ee10..07ccd2c1b 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings @@ -154,7 +154,7 @@ Your profile looks like this to them."; "Common.Controls.Timeline.Timestamp.Now" = "Now"; "Scene.AccountList.AddAccount" = "Add Account"; "Scene.AccountList.DismissAccountSwitcher" = "Dismiss Account Switcher"; -"Scene.AccountList.SwitchAccounts" = "Switch Accounts"; +"Scene.AccountList.TabBarHint" = "Current selected profile: %@. Double tap then hold to show account switcher"; "Scene.Bookmark.Title" = "Bookmarks"; "Scene.Compose.Accessibility.AppendAttachment" = "Add Attachment"; "Scene.Compose.Accessibility.AppendPoll" = "Add Poll";