Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions Sources/AlertKit/Extensions/SwiftUIExtension.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import SwiftUI
import UIKit

@available(iOS 13.0, *)
extension View {

public func alert(isPresent: Binding<Bool>, 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<Bool>,
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
Expand Down
2 changes: 1 addition & 1 deletion Sources/AlertKit/Views/AlertAppleMusic16View.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

@available(iOS 13, *)
public class AlertAppleMusic16View: UIView, AlertViewProtocol {
public class AlertAppleMusic16View: UIView, AlertViewProtocol, AlertViewInternalDismissProtocol {

open var dismissByTap: Bool = true
open var dismissInTime: Bool = true
Expand Down