TabPickerViewController: Refactor to not reference tab controller directly.
This commit is contained in:
@@ -137,9 +137,15 @@ class BrowserViewController: UIViewController
|
||||
|
||||
// Tabs button
|
||||
toolbarController.windowButton.addAction(UIAction(handler: { [unowned self] _ in
|
||||
let tabPickerController = TabPickerViewController(tabController: self.tabController)
|
||||
let tabPickerController = TabPickerViewController()
|
||||
tabPickerController.delegate = self
|
||||
tabPickerController.selectedTab = self.tab
|
||||
tabPickerController.selectedTabIdentifier = self.tab.identifier
|
||||
tabPickerController.tabIdentifiers = tabController.tabs.map { $0.identifier }
|
||||
tabPickerController.tabObserver = tabController.$tabs
|
||||
.receive(on: RunLoop.main)
|
||||
.sink(receiveValue: { (newTabs: [Tab]) in
|
||||
tabPickerController.tabIdentifiers = newTabs.map { $0.identifier }
|
||||
})
|
||||
|
||||
let navController = UINavigationController(rootViewController: tabPickerController)
|
||||
navController.modalPresentationStyle = .popover
|
||||
@@ -611,12 +617,28 @@ extension BrowserViewController: TabDelegate
|
||||
|
||||
extension BrowserViewController: TabPickerViewControllerDelegate
|
||||
{
|
||||
func tabPicker(_ picker: TabPickerViewController, didSelectTab tab: Tab) {
|
||||
func tabPicker(_ picker: TabPickerViewController, createNewTabWithURL url: URL?) {
|
||||
self.tab = tabController.createNewTab(url: url)
|
||||
picker.dismiss(animated: true)
|
||||
}
|
||||
|
||||
func tabPicker(_ picker: TabPickerViewController, tabInfoForIdentifier identifier: UUID) -> TabInfo {
|
||||
guard let tab = tabController.tab(forIdentifier: identifier) else { fatalError() }
|
||||
return tab.tabInfo
|
||||
}
|
||||
|
||||
func tabPicker(_ picker: TabPickerViewController, didSelectTabIdentifier tabIdentifier: UUID) {
|
||||
guard let tab = tabController.tab(forIdentifier: tabIdentifier) else { return }
|
||||
|
||||
self.tab = tab
|
||||
picker.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func tabPicker(_ picker: TabPickerViewController, willCloseTab tab: Tab) {
|
||||
func tabPicker(_ picker: TabPickerViewController, closeTabWithIdentifier tabIdentifier: UUID) {
|
||||
guard let tab = tabController.tab(forIdentifier: tabIdentifier) else { return }
|
||||
|
||||
tabController.closeTab(tab)
|
||||
|
||||
// Dismiss picker if current tab is closed using the picker
|
||||
if tab == self.tab {
|
||||
picker.dismiss(animated: true, completion: nil)
|
||||
|
||||
Reference in New Issue
Block a user