Skip to content

Commit

Permalink
Fixs bug with window
Browse files Browse the repository at this point in the history
  • Loading branch information
kopiev.ivan committed Oct 17, 2024
1 parent 4f29e31 commit b341454
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/DeeplinkRouter/BaseNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#if os(iOS)
import UIKit
import Combine
import SafariServices

public final class BaseNavigator: NavigatorProtocol {
Expand Down Expand Up @@ -37,18 +38,31 @@ public final class BaseNavigator: NavigatorProtocol {
isLoading ? showLoader() : hideLoader()
}

private var subscriptions: Set<AnyCancellable> = []

public init(window: UIWindow? = nil) {
if let window = window {
self.window = window
} else {
self.window = UIApplication.shared.windows.first { $0.isKeyWindow }
bindUIWindow()
}
}
}

// 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 }

Expand Down

0 comments on commit b341454

Please sign in to comment.