修复可能拿不到windowScene的情况

This commit is contained in:
xaoxuu 2023-08-21 18:11:50 +08:00
parent f68b0c3a9b
commit 69afc5dd6a
4 changed files with 7 additions and 8 deletions

View File

@ -52,9 +52,8 @@ extension AlertTarget {
self.navEvents[.onViewDidDisappear]?(self) self.navEvents[.onViewDidDisappear]?(self)
} }
// hide window // hide window
guard let window = view.window as? AlertWindow, let windowScene = windowScene else { return } guard let window = attachedWindow, let windowScene = windowScene ?? AppContext.windowScene else { return }
let count = window.alerts.count if window.alerts.count == 0 {
if count == 0 {
AppContext.alertWindow[windowScene] = nil AppContext.alertWindow[windowScene] = nil
UIView.animateLinear(duration: duration) { UIView.animateLinear(duration: duration) {
window.backgroundView.alpha = 0 window.backgroundView.alpha = 0

View File

@ -136,7 +136,7 @@ extension CapsuleTarget {
} }
@objc open func pop() { @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 let position = vm?.position ?? .top
AppContext.capsuleWindows[windowScene]?[position] = nil AppContext.capsuleWindows[windowScene]?[position] = nil
navEvents[.onViewWillDisappear]?(self) navEvents[.onViewWillDisappear]?(self)

View File

@ -31,13 +31,13 @@ class SheetWindow: Window {
extension SheetTarget { extension SheetTarget {
func getContextWindows() -> [SheetWindow] { func getContextWindows() -> [SheetWindow] {
guard let windowScene = windowScene else { guard let windowScene = windowScene ?? AppContext.windowScene else {
return [] return []
} }
return AppContext.sheetWindows[windowScene] ?? [] return AppContext.sheetWindows[windowScene] ?? []
} }
func setContextWindows(_ windows: [SheetWindow]) { func setContextWindows(_ windows: [SheetWindow]) {
guard let windowScene = windowScene else { guard let windowScene = windowScene ?? AppContext.windowScene else {
return return
} }
AppContext.sheetWindows[windowScene] = windows AppContext.sheetWindows[windowScene] = windows

View File

@ -38,13 +38,13 @@ class ToastWindow: Window {
extension ToastTarget { extension ToastTarget {
func getContextWindows() -> [ToastWindow] { func getContextWindows() -> [ToastWindow] {
guard let windowScene = windowScene else { guard let windowScene = windowScene ?? AppContext.windowScene else {
return [] return []
} }
return AppContext.toastWindows[windowScene] ?? [] return AppContext.toastWindows[windowScene] ?? []
} }
func setContextWindows(_ windows: [ToastWindow]) { func setContextWindows(_ windows: [ToastWindow]) {
guard let windowScene = windowScene else { guard let windowScene = windowScene ?? AppContext.windowScene else {
return return
} }
AppContext.toastWindows[windowScene] = windows AppContext.toastWindows[windowScene] = windows