From 69afc5dd6a23c110ba71bee630ed06137234aac8 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Mon, 21 Aug 2023 18:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=AF=E8=83=BD=E6=8B=BF?= =?UTF-8?q?=E4=B8=8D=E5=88=B0windowScene=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ProHUD/Alert/AlertManager.swift | 5 ++--- Sources/ProHUD/Capsule/CapsuleManager.swift | 2 +- Sources/ProHUD/Sheet/SheetWindow.swift | 4 ++-- Sources/ProHUD/Toast/ToastWindow.swift | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Sources/ProHUD/Alert/AlertManager.swift b/Sources/ProHUD/Alert/AlertManager.swift index a356cda..30ce4ac 100644 --- a/Sources/ProHUD/Alert/AlertManager.swift +++ b/Sources/ProHUD/Alert/AlertManager.swift @@ -52,9 +52,8 @@ extension AlertTarget { self.navEvents[.onViewDidDisappear]?(self) } // hide window - guard let window = view.window as? AlertWindow, let windowScene = windowScene else { return } - let count = window.alerts.count - if count == 0 { + guard let window = attachedWindow, let windowScene = windowScene ?? AppContext.windowScene else { return } + if window.alerts.count == 0 { AppContext.alertWindow[windowScene] = nil UIView.animateLinear(duration: duration) { window.backgroundView.alpha = 0 diff --git a/Sources/ProHUD/Capsule/CapsuleManager.swift b/Sources/ProHUD/Capsule/CapsuleManager.swift index 889dd42..e23be22 100644 --- a/Sources/ProHUD/Capsule/CapsuleManager.swift +++ b/Sources/ProHUD/Capsule/CapsuleManager.swift @@ -136,7 +136,7 @@ extension CapsuleTarget { } @objc open func pop() { - guard let window = attachedWindow, let windowScene = windowScene else { return } + guard let window = attachedWindow, let windowScene = windowScene ?? AppContext.windowScene else { return } let position = vm?.position ?? .top AppContext.capsuleWindows[windowScene]?[position] = nil navEvents[.onViewWillDisappear]?(self) diff --git a/Sources/ProHUD/Sheet/SheetWindow.swift b/Sources/ProHUD/Sheet/SheetWindow.swift index a1f34c1..2c2a8f8 100644 --- a/Sources/ProHUD/Sheet/SheetWindow.swift +++ b/Sources/ProHUD/Sheet/SheetWindow.swift @@ -31,13 +31,13 @@ class SheetWindow: Window { extension SheetTarget { func getContextWindows() -> [SheetWindow] { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return [] } return AppContext.sheetWindows[windowScene] ?? [] } func setContextWindows(_ windows: [SheetWindow]) { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return } AppContext.sheetWindows[windowScene] = windows diff --git a/Sources/ProHUD/Toast/ToastWindow.swift b/Sources/ProHUD/Toast/ToastWindow.swift index 11ea671..87ed9c4 100644 --- a/Sources/ProHUD/Toast/ToastWindow.swift +++ b/Sources/ProHUD/Toast/ToastWindow.swift @@ -38,13 +38,13 @@ class ToastWindow: Window { extension ToastTarget { func getContextWindows() -> [ToastWindow] { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return [] } return AppContext.toastWindows[windowScene] ?? [] } func setContextWindows(_ windows: [ToastWindow]) { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return } AppContext.toastWindows[windowScene] = windows