mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Introduce support for multiple windows on mac and iPad OS
Once the app starts the WindowManager is configured with SwiftUI's environment OpenWindowAction. It can then be used to register coordinators (that provide the toPresentable view) and an optional flow coordinator (as most of the screens are part of a flow, especially rooms). Once a coordinator is registed, the WindowManager invokes the OpenWindowAction which in turn makes the Application call its newly introduced WindowManagerWindowType WindowGroup's block to instantiate a new visual window rooting that view. The WindowManager is also responsible for wrapping the presentable in a disappearance block and clean up the coordinator stack. # Conflicts: # ElementX/Sources/Application/AppCoordinator.swift
This commit is contained in:
committed by
Stefan Ceriu
parent
91a10f4d51
commit
f1ef968975
@@ -18,6 +18,8 @@ class WindowManager: SecureWindowManagerProtocol {
|
||||
private(set) var overlayWindow: UIWindow!
|
||||
private(set) var globalSearchWindow: UIWindow!
|
||||
private(set) var alternateWindow: UIWindow!
|
||||
|
||||
private(set) var openWindowAction: OpenWindowAction!
|
||||
|
||||
var windows: [UIWindow] {
|
||||
[mainWindow, overlayWindow, globalSearchWindow, alternateWindow]
|
||||
@@ -29,6 +31,8 @@ class WindowManager: SecureWindowManagerProtocol {
|
||||
/// A duration that allows window switching to wait a couple of frames to avoid a transition through black.
|
||||
private let windowHideDelay = Duration.milliseconds(33)
|
||||
|
||||
private var coordinators: [WindowManagerWindowType: (coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?)] = [:]
|
||||
|
||||
init(appDelegate: AppDelegate) {
|
||||
self.appDelegate = appDelegate
|
||||
}
|
||||
@@ -54,6 +58,29 @@ class WindowManager: SecureWindowManagerProtocol {
|
||||
delegate?.windowManagerDidConfigureWindows(self)
|
||||
}
|
||||
|
||||
func configure(with openWindowAction: OpenWindowAction) {
|
||||
self.openWindowAction = openWindowAction
|
||||
}
|
||||
|
||||
func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType) {
|
||||
coordinators[type] = (coordinator, flowCoordinator)
|
||||
openWindowAction(value: type)
|
||||
}
|
||||
|
||||
func windowForType(_ type: WindowManagerWindowType) -> AnyView? {
|
||||
guard let coordinator = coordinators[type]?.coordinator else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return coordinator.toPresentable()
|
||||
}
|
||||
|
||||
func handleRoute(_ appRoute: AppRoute, windowType: WindowManagerWindowType) {
|
||||
if let flowCoordinator = coordinators[windowType]?.flowCoordinator {
|
||||
flowCoordinator.handleAppRoute(appRoute, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
func switchToMain() {
|
||||
mainWindow.isHidden = false
|
||||
overlayWindow.isHidden = false
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum WindowManagerWindowType: Hashable, Codable {
|
||||
case room(roomID: String)
|
||||
case settings
|
||||
}
|
||||
|
||||
protocol SecureWindowManagerDelegate: AnyObject {
|
||||
/// The window manager has configured its windows.
|
||||
func windowManagerDidConfigureWindows(_ windowManager: SecureWindowManagerProtocol)
|
||||
@@ -20,6 +25,12 @@ protocol SecureWindowManagerProtocol: WindowManagerProtocol {
|
||||
/// Configures the window manager to operate on the supplied scene.
|
||||
func configure(with windowScene: UIWindowScene)
|
||||
|
||||
func configure(with openWindowAction: OpenWindowAction)
|
||||
|
||||
func handleRoute(_ appRoute: AppRoute, windowType: WindowManagerWindowType)
|
||||
|
||||
func windowForType(_ type: WindowManagerWindowType) -> AnyView?
|
||||
|
||||
/// Shows the main and overlay window combo, hiding the alternate window.
|
||||
func switchToMain()
|
||||
|
||||
@@ -43,6 +54,8 @@ protocol WindowManagerProtocol: AnyObject, OrientationManagerProtocol {
|
||||
/// All the windows being managed
|
||||
var windows: [UIWindow] { get }
|
||||
|
||||
func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType)
|
||||
|
||||
/// Makes the global search window key. Used to get automatic text field focus.
|
||||
func showGlobalSearch()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user