Remote tabs: Fix bug where menu was out of sync with list of tabs

This commit is contained in:
James Magahern
2022-08-05 19:50:27 -07:00
parent a9801d9d56
commit 3b42984361

View File

@@ -140,12 +140,9 @@ class TabPickerViewController: UIViewController, UICollectionViewDelegate
} }
public func setTabInfos(_ infos: [TabInfo], forHost host: String) { public func setTabInfos(_ infos: [TabInfo], forHost host: String) {
let wasEmpty = tabIdentifiersByHost.isEmpty
tabIdentifiersByHost[host] = infos tabIdentifiersByHost[host] = infos
if wasEmpty { if host == selectedTabHost {
selectedTabHost = host
} else if host == selectedTabHost {
var snapshot = dataSource.snapshot() var snapshot = dataSource.snapshot()
snapshot.deleteAllItems() snapshot.deleteAllItems()
snapshot.appendSections([ 0 ]) snapshot.appendSections([ 0 ])
@@ -165,6 +162,10 @@ class TabPickerViewController: UIViewController, UICollectionViewDelegate
} }
hostPickerButton.menu = UIMenu(children: menuChildren) hostPickerButton.menu = UIMenu(children: menuChildren)
// Update list for whatever the selected item is
selectedTabHost = hostPickerButton.menu?.selectedElements.first?.title
if tabIdentifiersByHost.keys.count > 0 && tabIdentifiersByHost.keys.first != Self.localHostIdentifier { if tabIdentifiersByHost.keys.count > 0 && tabIdentifiersByHost.keys.first != Self.localHostIdentifier {
navigationItem.titleView = hostPickerButton navigationItem.titleView = hostPickerButton
} else { } else {
@@ -201,7 +202,7 @@ class TabPickerViewController: UIViewController, UICollectionViewDelegate
} }
private func didChangeSelectedTabHost(_ tabHost: String) { private func didChangeSelectedTabHost(_ tabHost: String) {
guard let tabIdentifiers = tabIdentifiersByHost[tabHost] else { return } guard let tabIdentifiers = tabIdentifiersByHost[tabHost] else { fatalError() }
var snapshot = dataSource.snapshot() var snapshot = dataSource.snapshot()
snapshot.deleteAllItems() snapshot.deleteAllItems()