From 8e31fb8df7d45f3fc918368189278927a15be67e Mon Sep 17 00:00:00 2001 From: mrevanzak Date: Sun, 7 Sep 2025 18:45:35 +0700 Subject: [PATCH 1/3] =?UTF-8?q?feat(AlertAppleMusic16View):=20make=20the?= =?UTF-8?q?=20iOS=2016=20alert=20conform=20to=20the=20internal=20dismiss?= =?UTF-8?q?=20protocol=20so=20=E2=80=9Cdismiss=20all=E2=80=9D=20works=20un?= =?UTF-8?q?iformly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/AlertKit/Views/AlertAppleMusic16View.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index b58062e..2f53698 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -1,7 +1,7 @@ import UIKit @available(iOS 13, *) -public class AlertAppleMusic16View: UIView, AlertViewProtocol { +public class AlertAppleMusic16View: UIView, AlertViewProtocol, AlertInternal, AlertViewInternalDismissProtocol { open var dismissByTap: Bool = true open var dismissInTime: Bool = true From 42a32b540237636f5c1db27da586d7e3ce3865ba Mon Sep 17 00:00:00 2001 From: mrevanzak Date: Sun, 7 Sep 2025 18:52:13 +0700 Subject: [PATCH 2/3] fix(alert): improve alert presentation logic to handle dismissals and state changes asynchronously --- .../Extensions/SwiftUIExtension.swift | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Sources/AlertKit/Extensions/SwiftUIExtension.swift b/Sources/AlertKit/Extensions/SwiftUIExtension.swift index 4f16b58..419f60a 100644 --- a/Sources/AlertKit/Extensions/SwiftUIExtension.swift +++ b/Sources/AlertKit/Extensions/SwiftUIExtension.swift @@ -1,16 +1,29 @@ import SwiftUI +import UIKit @available(iOS 13.0, *) extension View { - - public func alert(isPresent: Binding, view: AlertViewProtocol, completion: (()->Void)? = nil) -> some View { - if isPresent.wrappedValue { - let wrapperCompletion = { - isPresent.wrappedValue = false - completion?() - } - if let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first { - view.present(on: window, completion: wrapperCompletion) + + public func alert( + isPresent: Binding, + view: AlertViewProtocol, + completion: (() -> Void)? = nil + ) -> some View { + // Perform side effects asynchronously to avoid state changes during view updates + DispatchQueue.main.async { + if isPresent.wrappedValue { + let wrapperCompletion = { + isPresent.wrappedValue = false + completion?() + } + if let window = UIApplication.shared.windows.first(where: { + $0.isKeyWindow + }) { + view.present(on: window, completion: wrapperCompletion) + } + } else { + // Programmatically dismiss any active alerts when Binding flips to false + AlertKitAPI.dismissAllAlerts(completion: completion) } } return self From 933a7e82dee5df6f36d70976cf31a38a31536cce Mon Sep 17 00:00:00 2001 From: mrevanzak Date: Sun, 7 Sep 2025 19:12:59 +0700 Subject: [PATCH 3/3] fix: typo --- Sources/AlertKit/Views/AlertAppleMusic16View.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index 2f53698..92ce7ca 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -1,7 +1,7 @@ import UIKit @available(iOS 13, *) -public class AlertAppleMusic16View: UIView, AlertViewProtocol, AlertInternal, AlertViewInternalDismissProtocol { +public class AlertAppleMusic16View: UIView, AlertViewProtocol, AlertViewInternalDismissProtocol { open var dismissByTap: Bool = true open var dismissInTime: Bool = true