Have the UserIndicatorController use a separate window, switch to using one single instance throughout the application

This commit is contained in:
Stefan Ceriu
2023-11-09 15:10:50 +02:00
committed by Stefan Ceriu
parent 1102beb3dd
commit 4b26a798dc
44 changed files with 210 additions and 221 deletions
@@ -16,9 +16,7 @@
import SwiftUI
class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol, CustomStringConvertible {
private let rootCoordinator: CoordinatorProtocol
class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol {
private var dismissalTimer: Timer?
private var displayTimes = [String: Date]()
private var delayedIndicators = Set<String>()
@@ -42,14 +40,12 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
@Published var alertInfo: AlertInfo<UUID>?
init(rootCoordinator: CoordinatorProtocol) {
self.rootCoordinator = rootCoordinator
}
func toPresentable() -> AnyView {
AnyView(
UserIndicatorPresenter(userIndicatorController: self, rootView: rootCoordinator.toPresentable())
)
var window: UIWindow? {
didSet {
let hostingController = UIHostingController(rootView: UserIndicatorPresenter(userIndicatorController: self))
hostingController.view.backgroundColor = .clear
window?.rootViewController = hostingController
}
}
func submitIndicator(_ indicator: UserIndicator, delay: Duration?) {
@@ -95,12 +91,6 @@ class UserIndicatorController: ObservableObject, UserIndicatorControllerProtocol
}
}
// MARK: - CustomStringConvertible
var description: String {
"UserIndicatorController(\(String(describing: rootCoordinator)))"
}
// MARK: - Private
private func enqueue(indicator: UserIndicator) {
@@ -14,13 +14,15 @@
// limitations under the License.
//
import Foundation
import UIKit
// sourcery: AutoMockable
protocol UserIndicatorControllerProtocol: CoordinatorProtocol {
func submitIndicator(_ indicator: UserIndicator, delay: Duration?)
func retractIndicatorWithId(_ id: String)
func retractAllIndicators()
var window: UIWindow? { get set }
var alertInfo: AlertInfo<UUID>? { get set }
}
@@ -18,14 +18,11 @@ import SwiftUI
struct UserIndicatorPresenter: View {
@ObservedObject var userIndicatorController: UserIndicatorController
let rootView: AnyView
var body: some View {
ZStack(alignment: .top) {
rootView
indicatorViewFor(indicator: userIndicatorController.activeIndicator)
}
.animation(.elementDefault, value: userIndicatorController.activeIndicator)
indicatorViewFor(indicator: userIndicatorController.activeIndicator)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.animation(.elementDefault, value: userIndicatorController.activeIndicator)
}
@ViewBuilder