From b3414543a78e481d2cc45ecb810fbb4846f507fa Mon Sep 17 00:00:00 2001 From: "kopiev.ivan" Date: Thu, 17 Oct 2024 17:10:18 +0300 Subject: [PATCH] Fixs bug with window --- Sources/DeeplinkRouter/BaseNavigator.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/DeeplinkRouter/BaseNavigator.swift b/Sources/DeeplinkRouter/BaseNavigator.swift index a8af439..bed0ce9 100644 --- a/Sources/DeeplinkRouter/BaseNavigator.swift +++ b/Sources/DeeplinkRouter/BaseNavigator.swift @@ -7,6 +7,7 @@ #if os(iOS) import UIKit +import Combine import SafariServices public final class BaseNavigator: NavigatorProtocol { @@ -37,11 +38,14 @@ public final class BaseNavigator: NavigatorProtocol { isLoading ? showLoader() : hideLoader() } + private var subscriptions: Set = [] + public init(window: UIWindow? = nil) { if let window = window { self.window = window } else { self.window = UIApplication.shared.windows.first { $0.isKeyWindow } + bindUIWindow() } } } @@ -49,6 +53,16 @@ public final class BaseNavigator: NavigatorProtocol { // MARK: - Вспомогательные методы private extension BaseNavigator { + func bindUIWindow() { + NotificationCenter.default + .publisher(for: UIWindow.didBecomeKeyNotification) + .compactMap { $0.object as? UIWindow } + .sink { [weak self] window in + print("Window became key: \(window)") + self?.window = window + }.store(in: &subscriptions) + } + func showLoader() { guard let window = window else { return }