Fix Cmd+3 not properly selecting Explore tab
Having MainSidebarViewController.Item.explore and .tab(.explore) was a mistake and made it easy to accidentally use the wrong one for the key command, so use .tab(.explore) for everything. Closes #519
This commit is contained in:
parent
eb89aec00f
commit
c5f42719a0
|
@ -32,7 +32,7 @@ struct MenuController {
|
||||||
static let sidebarItemKeyCommands: [UIKeyCommand] = [
|
static let sidebarItemKeyCommands: [UIKeyCommand] = [
|
||||||
sidebarCommand(item: .tab(.timelines), command: "1", action: #selector(MainSplitViewController.handleSidebarCommandTimelines)),
|
sidebarCommand(item: .tab(.timelines), command: "1", action: #selector(MainSplitViewController.handleSidebarCommandTimelines)),
|
||||||
sidebarCommand(item: .tab(.notifications), command: "2", action: #selector(MainSplitViewController.handleSidebarCommandNotifications)),
|
sidebarCommand(item: .tab(.notifications), command: "2", action: #selector(MainSplitViewController.handleSidebarCommandNotifications)),
|
||||||
sidebarCommand(item: .explore, command: "3", action: #selector(MainSplitViewController.handleSidebarCommandExplore)),
|
sidebarCommand(item: .tab(.explore), command: "3", action: #selector(MainSplitViewController.handleSidebarCommandExplore)),
|
||||||
sidebarCommand(item: .bookmarks, command: "4", action: #selector(MainSplitViewController.handleSidebarCommandBookmarks)),
|
sidebarCommand(item: .bookmarks, command: "4", action: #selector(MainSplitViewController.handleSidebarCommandBookmarks)),
|
||||||
sidebarCommand(item: .tab(.myProfile), command: "5", action: #selector(MainSplitViewController.handleSidebarCommandMyProfile)),
|
sidebarCommand(item: .tab(.myProfile), command: "5", action: #selector(MainSplitViewController.handleSidebarCommandMyProfile)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -43,7 +43,7 @@ class MainSidebarViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
var exploreTabItems: [Item] {
|
var exploreTabItems: [Item] {
|
||||||
var items: [Item] = [.explore, .bookmarks, .favorites]
|
var items: [Item] = [.tab(.explore), .bookmarks, .favorites]
|
||||||
let snapshot = dataSource.snapshot()
|
let snapshot = dataSource.snapshot()
|
||||||
for case let .list(list) in snapshot.itemIdentifiers(inSection: .lists) {
|
for case let .list(list) in snapshot.itemIdentifiers(inSection: .lists) {
|
||||||
items.append(.list(list))
|
items.append(.list(list))
|
||||||
|
@ -170,7 +170,7 @@ class MainSidebarViewController: UIViewController {
|
||||||
snapshot.appendItems([
|
snapshot.appendItems([
|
||||||
.tab(.timelines),
|
.tab(.timelines),
|
||||||
.tab(.notifications),
|
.tab(.notifications),
|
||||||
.explore,
|
.tab(.explore),
|
||||||
.bookmarks,
|
.bookmarks,
|
||||||
.favorites,
|
.favorites,
|
||||||
.tab(.myProfile)
|
.tab(.myProfile)
|
||||||
|
@ -302,7 +302,7 @@ class MainSidebarViewController: UIViewController {
|
||||||
return UserActivityManager.checkNotificationsActivity(mode: Preferences.shared.defaultNotificationsMode, accountID: id)
|
return UserActivityManager.checkNotificationsActivity(mode: Preferences.shared.defaultNotificationsMode, accountID: id)
|
||||||
case .tab(.compose):
|
case .tab(.compose):
|
||||||
return UserActivityManager.newPostActivity(accountID: id)
|
return UserActivityManager.newPostActivity(accountID: id)
|
||||||
case .explore:
|
case .tab(.explore):
|
||||||
return UserActivityManager.searchActivity(query: nil, accountID: id)
|
return UserActivityManager.searchActivity(query: nil, accountID: id)
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
return UserActivityManager.bookmarksActivity(accountID: id)
|
return UserActivityManager.bookmarksActivity(accountID: id)
|
||||||
|
@ -340,7 +340,7 @@ extension MainSidebarViewController {
|
||||||
}
|
}
|
||||||
enum Item: Hashable {
|
enum Item: Hashable {
|
||||||
case tab(MainTabBarViewController.Tab)
|
case tab(MainTabBarViewController.Tab)
|
||||||
case explore, bookmarks, favorites
|
case bookmarks, favorites
|
||||||
case listsHeader, list(List), addList
|
case listsHeader, list(List), addList
|
||||||
case savedHashtagsHeader, savedHashtag(String), addSavedHashtag
|
case savedHashtagsHeader, savedHashtag(String), addSavedHashtag
|
||||||
case savedInstancesHeader, savedInstance(URL), addSavedInstance
|
case savedInstancesHeader, savedInstance(URL), addSavedInstance
|
||||||
|
@ -349,8 +349,6 @@ extension MainSidebarViewController {
|
||||||
switch self {
|
switch self {
|
||||||
case let .tab(tab):
|
case let .tab(tab):
|
||||||
return tab.title
|
return tab.title
|
||||||
case .explore:
|
|
||||||
return "Explore"
|
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
return "Bookmarks"
|
return "Bookmarks"
|
||||||
case .favorites:
|
case .favorites:
|
||||||
|
@ -380,8 +378,6 @@ extension MainSidebarViewController {
|
||||||
switch self {
|
switch self {
|
||||||
case let .tab(tab):
|
case let .tab(tab):
|
||||||
return tab.imageName
|
return tab.imageName
|
||||||
case .explore:
|
|
||||||
return "magnifyingglass"
|
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
return "bookmark"
|
return "bookmark"
|
||||||
case .favorites:
|
case .favorites:
|
||||||
|
|
|
@ -279,7 +279,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
$0.1 > $1.1
|
$0.1 > $1.1
|
||||||
}
|
}
|
||||||
if let mostRecentExploreItem = mostRecentExploreItem?.0,
|
if let mostRecentExploreItem = mostRecentExploreItem?.0,
|
||||||
mostRecentExploreItem != .explore {
|
mostRecentExploreItem != .tab(.explore) {
|
||||||
let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController
|
let exploreNav = tabBarViewController.viewController(for: .explore) as! UINavigationController
|
||||||
// Pop back to root, so we're appending to the Explore VC instead of some other VC
|
// Pop back to root, so we're appending to the Explore VC instead of some other VC
|
||||||
exploreNav.popToRootViewController(animated: false)
|
exploreNav.popToRootViewController(animated: false)
|
||||||
|
@ -292,11 +292,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
case nil:
|
case nil:
|
||||||
break
|
break
|
||||||
|
|
||||||
case let .tab(tab):
|
case .tab(.explore):
|
||||||
// sidebar items that map 1 <-> 1 can be transferred directly
|
|
||||||
tabBarViewController.select(tab: tab, dismissPresented: false)
|
|
||||||
|
|
||||||
case .explore:
|
|
||||||
// Search sidebar item maps to the Explore tab with the search controller/results visible
|
// Search sidebar item maps to the Explore tab with the search controller/results visible
|
||||||
// The nav stack can't be copied directly, since the split VC uses a different SearchViewController
|
// The nav stack can't be copied directly, since the split VC uses a different SearchViewController
|
||||||
// so that explore items aren't shown multiple times.
|
// so that explore items aren't shown multiple times.
|
||||||
|
@ -335,10 +331,14 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer the navigation stack, dropping the search VC, to keep anything the user has opened
|
// Transfer the navigation stack, dropping the search VC, to keep anything the user has opened
|
||||||
transferNavigationStack(from: .explore, to: exploreNav, dropFirst: true, append: true)
|
transferNavigationStack(from: .tab(.explore), to: exploreNav, dropFirst: true, append: true)
|
||||||
|
|
||||||
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
||||||
|
|
||||||
|
case let .tab(tab):
|
||||||
|
// sidebar items that map 1 <-> 1 can be transferred directly
|
||||||
|
tabBarViewController.select(tab: tab, dismissPresented: false)
|
||||||
|
|
||||||
case .bookmarks, .favorites, .list(_), .savedHashtag(_), .savedInstance(_):
|
case .bookmarks, .favorites, .list(_), .savedHashtag(_), .savedInstance(_):
|
||||||
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
tabBarViewController.select(tab: .explore, dismissPresented: false)
|
||||||
// Make sure the Explore VC doesn't show its search bar when it appears, in case the user was previously
|
// Make sure the Explore VC doesn't show its search bar when it appears, in case the user was previously
|
||||||
|
@ -396,9 +396,9 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
// For other items, the 2nd VC in the nav stack determines which sidebar item they map to.
|
// For other items, the 2nd VC in the nav stack determines which sidebar item they map to.
|
||||||
// Search screen has special considerations, all others can be transferred directly.
|
// Search screen has special considerations, all others can be transferred directly.
|
||||||
if tabNavigationStack.count == 1 || ((tabNavigationStack.first as? ExploreViewController)?.searchController?.isActive ?? false) {
|
if tabNavigationStack.count == 1 || ((tabNavigationStack.first as? ExploreViewController)?.searchController?.isActive ?? false) {
|
||||||
exploreItem = .explore
|
exploreItem = .tab(.explore)
|
||||||
// reuse the existing VC, if there is one
|
// reuse the existing VC, if there is one
|
||||||
let searchVC = getOrCreateNavigationStack(item: .explore).first! as! InlineTrendsViewController
|
let searchVC = getOrCreateNavigationStack(item: .tab(.explore)).first! as! InlineTrendsViewController
|
||||||
// load the view so that the search controller is accessible
|
// load the view so that the search controller is accessible
|
||||||
searchVC.loadViewIfNeeded()
|
searchVC.loadViewIfNeeded()
|
||||||
let explore = tabNavigationStack.first as! ExploreViewController
|
let explore = tabNavigationStack.first as! ExploreViewController
|
||||||
|
@ -426,16 +426,16 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
||||||
case let instanceVC as InstanceTimelineViewController:
|
case let instanceVC as InstanceTimelineViewController:
|
||||||
exploreItem = .savedInstance(instanceVC.instanceURL)
|
exploreItem = .savedInstance(instanceVC.instanceURL)
|
||||||
case is TrendsViewController:
|
case is TrendsViewController:
|
||||||
exploreItem = .explore
|
exploreItem = .tab(.explore)
|
||||||
// skip transferring the ExploreViewController and TrendsViewController
|
// skip transferring the ExploreViewController and TrendsViewController
|
||||||
skipFirst = 2
|
skipFirst = 2
|
||||||
// prepend the InlineTrendsViewController
|
// prepend the InlineTrendsViewController
|
||||||
toPrepend = getOrCreateNavigationStack(item: .explore).first!
|
toPrepend = getOrCreateNavigationStack(item: .tab(.explore)).first!
|
||||||
default:
|
default:
|
||||||
// transfer the navigation stack prepending, the existing explore VC
|
// transfer the navigation stack prepending, the existing explore VC
|
||||||
// if there was other stuff on the explore stack, it will get discarded
|
// if there was other stuff on the explore stack, it will get discarded
|
||||||
toPrepend = getOrCreateNavigationStack(item: .explore).first!
|
toPrepend = getOrCreateNavigationStack(item: .tab(.explore)).first!
|
||||||
exploreItem = .explore
|
exploreItem = .tab(.explore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transferNavigationStack(from: tabNavController, to: exploreItem!, skipFirst: skipFirst, prepend: toPrepend)
|
transferNavigationStack(from: tabNavController, to: exploreItem!, skipFirst: skipFirst, prepend: toPrepend)
|
||||||
|
@ -502,10 +502,10 @@ fileprivate extension MainSidebarViewController.Item {
|
||||||
@MainActor
|
@MainActor
|
||||||
func createRootViewController(_ mastodonController: MastodonController) -> UIViewController? {
|
func createRootViewController(_ mastodonController: MastodonController) -> UIViewController? {
|
||||||
switch self {
|
switch self {
|
||||||
|
case .tab(.explore):
|
||||||
|
return InlineTrendsViewController(mastodonController: mastodonController)
|
||||||
case let .tab(tab):
|
case let .tab(tab):
|
||||||
return tab.createViewController(mastodonController)
|
return tab.createViewController(mastodonController)
|
||||||
case .explore:
|
|
||||||
return InlineTrendsViewController(mastodonController: mastodonController)
|
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
return BookmarksViewController(mastodonController: mastodonController)
|
return BookmarksViewController(mastodonController: mastodonController)
|
||||||
case .favorites:
|
case .favorites:
|
||||||
|
@ -562,7 +562,7 @@ extension MainSplitViewController: TuskerRootViewController {
|
||||||
case .myProfile:
|
case .myProfile:
|
||||||
item = .tab(.myProfile)
|
item = .tab(.myProfile)
|
||||||
case .explore:
|
case .explore:
|
||||||
item = .explore
|
item = .tab(.explore)
|
||||||
case .bookmarks:
|
case .bookmarks:
|
||||||
item = .bookmarks
|
item = .bookmarks
|
||||||
case .list(id: let id):
|
case .list(id: let id):
|
||||||
|
@ -616,8 +616,8 @@ extension MainSplitViewController: TuskerRootViewController {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sidebar.selectedItem != .explore {
|
if sidebar.selectedItem != .tab(.explore) {
|
||||||
select(newItem: .explore, oldItem: sidebar.selectedItem)
|
select(newItem: .tab(.explore), oldItem: sidebar.selectedItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let searchViewController = secondaryNavController.viewControllers.first as? InlineTrendsViewController else {
|
guard let searchViewController = secondaryNavController.viewControllers.first as? InlineTrendsViewController else {
|
||||||
|
|
Loading…
Reference in New Issue