修复可能拿不到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)
}
// 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

View File

@ -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)

View File

@ -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

View File

@ -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