TabPickerViewController: Remote tab UI

This commit is contained in:
James Magahern
2022-08-05 15:56:30 -07:00
parent 1db6cf54a9
commit 61773b97db
2 changed files with 81 additions and 18 deletions

View File

@@ -139,20 +139,38 @@ class BrowserViewController: UIViewController
toolbarController.windowButton.addAction(UIAction(handler: { [unowned self] _ in
let tabPickerController = TabPickerViewController()
tabPickerController.delegate = self
tabPickerController.title = "Tabs"
tabPickerController.tabBarItem.image = UIImage(systemName: "rectangle.on.rectangle")
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 }
tabPickerController.setTabIdentifiers(newTabs.map { $0.identifier }, forHost: TabPickerViewController.localHostIdentifier)
})
let navController = UINavigationController(rootViewController: tabPickerController)
navController.modalPresentationStyle = .popover
navController.popoverPresentationController?.sourceView = self.toolbarController.windowButton
navController.popoverPresentationController?.delegate = self
// Set localhost tabs
let tabIdentifiers = tabController.tabs.map { $0.identifier }
tabPickerController.setTabIdentifiers(tabIdentifiers, forHost: TabPickerViewController.localHostIdentifier)
tabPickerController.selectedTabHost = TabPickerViewController.localHostIdentifier
let remoteTabPickerController = TabPickerViewController()
remoteTabPickerController.delegate = self
remoteTabPickerController.title = "Remote Tabs"
remoteTabPickerController.tabBarItem.image = UIImage(systemName: "icloud")
remoteTabPickerController.newTabButton.isEnabled = false
remoteTabPickerController.editButtonItem.isEnabled = false
let tabBarController = UITabBarController(nibName: nil, bundle: nil)
tabBarController.viewControllers = [
UINavigationController(rootViewController: tabPickerController),
UINavigationController(rootViewController: remoteTabPickerController)
]
tabBarController.modalPresentationStyle = .popover
tabBarController.popoverPresentationController?.sourceView = self.toolbarController.windowButton
tabBarController.popoverPresentationController?.delegate = self
self.present(navController, animated: true, completion: nil)
self.present(tabBarController, animated: true, completion: nil)
}), for: .touchUpInside)
let newTabAction = UIAction { [unowned self] action in