From 62743c17b1e38cfa52965fdcd202dbc0940d4386 Mon Sep 17 00:00:00 2001 From: nikolajjsj <10490273+nikolajjsj@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:59:46 +0200 Subject: [PATCH 01/16] Add Feedster app to apps-using section --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index eaf8886..25c801e 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ For UIKit & SwiftUI call this: ```swift AlertKitAPI.present( - title: "Added to Library", - icon: .done, - style: .iOS17AppleMusic, + title: "Added to Library", + icon: .done, + style: .iOS17AppleMusic, haptic: .success ) ``` @@ -20,7 +20,7 @@ Available 2 styles: ```swift public enum AlertViewStyle { - + case iOS16AppleMusic case iOS17AppleMusic } @@ -52,8 +52,8 @@ public enum AlertViewStyle { ## Navigate - [Installation](#installation) - - [Swift Package Manager](#swift-package-manager) - - [CocoaPods](#cocoapods) + - [Swift Package Manager](#swift-package-manager) + - [CocoaPods](#cocoapods) - [SwiftUI](#swiftui) - [Customisation](#customisation) - [Apps Using](#apps-using) @@ -64,7 +64,7 @@ Ready to use on iOS 13+. Supports iOS and visionOS. Working with `UIKit` and `Sw ### Swift Package Manager -In Xcode go to Project -> Your Project Name -> `Package Dependencies` -> Tap *Plus*. Insert url: +In Xcode go to Project -> Your Project Name -> `Package Dependencies` -> Tap _Plus_. Insert url: ``` https://github.com/sparrowcode/AlertKit @@ -89,6 +89,7 @@ This is an outdated way of doing things. I advise you to use [SPM](#swift-packag ```ruby pod 'SPAlert' ``` + ### Manually @@ -97,7 +98,7 @@ If you prefer not to use any of dependency managers, you can integrate manually. ## SwiftUI -You can use basic way via AlertKitAPI or call via modifier: +You can use basic way via AlertKitAPI or call via modifier: ```swift let alertView = AlertAppleMusic17View(title: "Hello", subtitle: nil, icon: .done) @@ -108,7 +109,7 @@ VStack {} ## Customisation -If you need customisation fonts, icon, colors or any other, make view: +If you need customisation fonts, icon, colors or any other, make view: ```swift let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done) @@ -121,6 +122,7 @@ alertView.titleLabel.textColor = .white ## Apps Using

+ From 30228c31758799cb5f59da3c45e090e78e7282ca Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 17 Oct 2023 16:07:51 +0300 Subject: [PATCH 02/16] Fixed blur style for iOS17 preset. --- SPAlert.podspec | 2 +- Sources/AlertKit/Views/AlertAppleMusic17View.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SPAlert.podspec b/SPAlert.podspec index 26098b3..be5fc5d 100644 --- a/SPAlert.podspec +++ b/SPAlert.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'SPAlert' - s.version = '5.1.2' + s.version = '5.1.4' s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.' s.homepage = 'https://github.com/sparrowcode/AlertKit' s.source = { :git => 'https://github.com/sparrowcode/AlertKit.git', :tag => s.version } diff --git a/Sources/AlertKit/Views/AlertAppleMusic17View.swift b/Sources/AlertKit/Views/AlertAppleMusic17View.swift index 94e3dd8..e6f10a3 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic17View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic17View.swift @@ -38,7 +38,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { hostView.isUserInteractionEnabled = false return hostView #else - let view = UIVisualEffectView(effect: UIBlurEffect()) + let view = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial)) view.isUserInteractionEnabled = false return view #endif From 72ac00d3798c506b6befa3cb7f68841fb18ba6aa Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 17 Oct 2023 16:21:01 +0300 Subject: [PATCH 03/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25c801e..2124ccc 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,6 @@ alertView.titleLabel.textColor = .white ## Apps Using

- @@ -131,6 +130,7 @@ alertView.titleLabel.textColor = .white +

If you use a `AlertKit`, add your app via Pull Request. From 64dd8516754b0665ae4cce543ddf0a830f6ecbf5 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 17 Oct 2023 16:21:56 +0300 Subject: [PATCH 04/16] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2124ccc..446a658 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,6 @@ alertView.titleLabel.textColor = .white -

From 8702253d9a46459e8e232ebf613e40664d3b54a8 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 31 Oct 2023 13:45:15 +0300 Subject: [PATCH 05/16] Added dismiss all alerts method. --- SPAlert.podspec | 2 +- Sources/AlertKit/AlertKitAPI.swift | 10 ++++++++++ Sources/AlertKit/Views/AlertViewProtocol.swift | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/SPAlert.podspec b/SPAlert.podspec index be5fc5d..4dbe57f 100644 --- a/SPAlert.podspec +++ b/SPAlert.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'SPAlert' - s.version = '5.1.4' + s.version = '5.1.5' s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.' s.homepage = 'https://github.com/sparrowcode/AlertKit' s.source = { :git => 'https://github.com/sparrowcode/AlertKit.git', :tag => s.version } diff --git a/Sources/AlertKit/AlertKitAPI.swift b/Sources/AlertKit/AlertKitAPI.swift index 9ccd8dc..022f54f 100644 --- a/Sources/AlertKit/AlertKitAPI.swift +++ b/Sources/AlertKit/AlertKitAPI.swift @@ -25,4 +25,14 @@ public enum AlertKitAPI { #endif } } + + public static func dismissAllAlerts() { + for window in UIApplication.shared.windows { + for view in window.subviews { + if let view = view as? AlertViewProtocol { + view.dismiss() + } + } + } + } } diff --git a/Sources/AlertKit/Views/AlertViewProtocol.swift b/Sources/AlertKit/Views/AlertViewProtocol.swift index e0e0f1a..e4cbecb 100644 --- a/Sources/AlertKit/Views/AlertViewProtocol.swift +++ b/Sources/AlertKit/Views/AlertViewProtocol.swift @@ -3,6 +3,7 @@ import UIKit public protocol AlertViewProtocol { func present(on view: UIView, completion: @escaping ()->Void) + func dismiss() var completion: (() -> Void)? { get set } } From 84a2c557319e7acc8bcad885ce637ffe5ae108c4 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 31 Oct 2023 13:48:55 +0300 Subject: [PATCH 06/16] Update README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 446a658..8d892b7 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ public enum AlertViewStyle { - [Swift Package Manager](#swift-package-manager) - [CocoaPods](#cocoapods) - [SwiftUI](#swiftui) +- [Present & Dismiss](#present-dismiss) - [Customisation](#customisation) - [Apps Using](#apps-using) @@ -119,6 +120,24 @@ alertView.titleLabel.font = UIFont.systemFont(ofSize: 21) alertView.titleLabel.textColor = .white ``` +## Present & Dismiss + +You can present and dismiss alerts manually via view. + +```swift +let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done) +alertView.present(on: self) + +// and dismiss +alertView.dismiss() +``` + +For dismiss all alerts that was presented: + +```swift +AlertKitAPI.dismissAllAlerts() +``` + ## Apps Using

From 7684bcde1d34092cedb2710bcc967839797fc163 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 31 Oct 2023 13:49:13 +0300 Subject: [PATCH 07/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d892b7..8b88702 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ or adding it to the `dependencies` of your `Package.swift`: ```swift dependencies: [ - .package(url: "https://github.com/sparrowcode/AlertKit", .upToNextMajor(from: "5.1.1")) + .package(url: "https://github.com/sparrowcode/AlertKit", .upToNextMajor(from: "5.1.5")) ] ``` From fa54349114decee56ded9797a7229137b4f3b0d5 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 31 Oct 2023 14:12:20 +0300 Subject: [PATCH 08/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b88702..8540c9e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ public enum AlertViewStyle { - [Swift Package Manager](#swift-package-manager) - [CocoaPods](#cocoapods) - [SwiftUI](#swiftui) -- [Present & Dismiss](#present-dismiss) +- [Present & Dismiss](#present--dismiss) - [Customisation](#customisation) - [Apps Using](#apps-using) From 6bd8a8aab893afacf28396a0fa12c598ab400742 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Wed, 1 Nov 2023 14:29:07 +0300 Subject: [PATCH 09/16] Updated completions way. --- SPAlert.podspec | 2 +- Sources/AlertKit/AlertKitAPI.swift | 22 +++++++++++++++++-- .../Extensions/SwiftUIExtension.swift | 9 ++++---- .../Views/AlertAppleMusic16View.swift | 14 ++++++------ .../Views/AlertAppleMusic17View.swift | 14 ++++++------ .../AlertKit/Views/AlertViewProtocol.swift | 11 ++-------- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/SPAlert.podspec b/SPAlert.podspec index 4dbe57f..a452884 100644 --- a/SPAlert.podspec +++ b/SPAlert.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'SPAlert' - s.version = '5.1.5' + s.version = '5.1.6' s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.' s.homepage = 'https://github.com/sparrowcode/AlertKit' s.source = { :git => 'https://github.com/sparrowcode/AlertKit.git', :tag => s.version } diff --git a/Sources/AlertKit/AlertKitAPI.swift b/Sources/AlertKit/AlertKitAPI.swift index 022f54f..e6218aa 100644 --- a/Sources/AlertKit/AlertKitAPI.swift +++ b/Sources/AlertKit/AlertKitAPI.swift @@ -26,13 +26,31 @@ public enum AlertKitAPI { } } - public static func dismissAllAlerts() { + public static func dismissAllAlerts(completion: (() -> Void)? = nil) { + + var alertViews: [AlertViewProtocol] = [] + for window in UIApplication.shared.windows { for view in window.subviews { if let view = view as? AlertViewProtocol { - view.dismiss() + alertViews.append(view) } } } + + if alertViews.isEmpty { + completion?() + } else { + for (index, view) in alertViews.enumerated() { + if index == .zero { + view.dismiss(completion: completion) + } else { + view.dismiss(completion: nil) + } + } + alertViews.first?.dismiss { + completion?() + } + } } } diff --git a/Sources/AlertKit/Extensions/SwiftUIExtension.swift b/Sources/AlertKit/Extensions/SwiftUIExtension.swift index c1a2bb5..4f16b58 100644 --- a/Sources/AlertKit/Extensions/SwiftUIExtension.swift +++ b/Sources/AlertKit/Extensions/SwiftUIExtension.swift @@ -3,15 +3,14 @@ import SwiftUI @available(iOS 13.0, *) extension View { - public func alert(isPresent: Binding, view: AlertViewProtocol) -> some View { + public func alert(isPresent: Binding, view: AlertViewProtocol, completion: (()->Void)? = nil) -> some View { if isPresent.wrappedValue { - let alertCompletion = view.completion - let completion = { + let wrapperCompletion = { isPresent.wrappedValue = false - alertCompletion?() + completion?() } if let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first { - view.present(on: window, completion: completion) + view.present(on: window, completion: wrapperCompletion) } } return self diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index df83b68..c5df8be 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -23,8 +23,6 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { fileprivate var presentDismissDuration: TimeInterval = 0.2 fileprivate var presentDismissScale: CGFloat = 0.8 - open var completion: (() -> Void)? = nil - private lazy var backgroundView: UIVisualEffectView = { let view: UIVisualEffectView = { #if !os(tvOS) @@ -124,8 +122,7 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { fatalError("init(coder:) has not been implemented") } - open func present(on view: UIView, completion: @escaping ()->Void = {}) { - self.completion = completion + open func present(on view: UIView, completion: (()->Void)? = nil) { self.viewForPresent = view viewForPresent?.addSubview(self) guard let viewForPresent = viewForPresent else { return } @@ -156,19 +153,22 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { if self.dismissInTime { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) { - self.dismiss() + // If dismiss manually no need call original completion. + if self.alpha != 0 { + self.dismiss(completion: completion) + } } } }) } - @objc open func dismiss() { + @objc open func dismiss(completion: (()->Void)? = nil) { UIView.animate(withDuration: presentDismissDuration, animations: { self.alpha = 0 self.transform = self.transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale) }, completion: { [weak self] finished in self?.removeFromSuperview() - self?.completion?() + completion?() }) } diff --git a/Sources/AlertKit/Views/AlertAppleMusic17View.swift b/Sources/AlertKit/Views/AlertAppleMusic17View.swift index e6f10a3..968052b 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic17View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic17View.swift @@ -28,8 +28,6 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { fileprivate var presentDismissDuration: TimeInterval = 0.2 fileprivate var presentDismissScale: CGFloat = 0.8 - open var completion: (() -> Void)? = nil - private lazy var backgroundView: UIView = { #if os(visionOS) let swiftUIView = VisionGlassBackgroundView(cornerRadius: 12) @@ -126,8 +124,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { fatalError("init(coder:) has not been implemented") } - open func present(on view: UIView, completion: @escaping ()->Void = {}) { - self.completion = completion + open func present(on view: UIView, completion: (()->Void)? = nil) { self.viewForPresent = view viewForPresent?.addSubview(self) guard let viewForPresent = viewForPresent else { return } @@ -164,19 +161,22 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { if self.dismissInTime { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) { - self.dismiss() + // If dismiss manually no need call original completion. + if self.alpha != 0 { + self.dismiss(completion: completion) + } } } }) } - @objc open func dismiss() { + @objc open func dismiss(completion: (()->Void)? = nil) { UIView.animate(withDuration: presentDismissDuration, animations: { self.alpha = 0 self.transform = self.transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale) }, completion: { [weak self] finished in self?.removeFromSuperview() - self?.completion?() + completion?() }) } diff --git a/Sources/AlertKit/Views/AlertViewProtocol.swift b/Sources/AlertKit/Views/AlertViewProtocol.swift index e4cbecb..19d1e6c 100644 --- a/Sources/AlertKit/Views/AlertViewProtocol.swift +++ b/Sources/AlertKit/Views/AlertViewProtocol.swift @@ -2,13 +2,6 @@ import UIKit public protocol AlertViewProtocol { - func present(on view: UIView, completion: @escaping ()->Void) - func dismiss() - - var completion: (() -> Void)? { get set } -} - -extension AlertViewProtocol where Self: UIView { - - func present(on view: UIView, completion: @escaping ()->Void = {}) {} + func present(on view: UIView, completion: (()->Void)?) + func dismiss(completion: (()->Void)?) } From 3c7acb28451f1b1d2b9d815280ab1276963544e7 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Wed, 1 Nov 2023 18:02:00 +0300 Subject: [PATCH 10/16] Fix layout bug when trigger in any time. --- Sources/AlertKit/Views/AlertAppleMusic16View.swift | 2 ++ Sources/AlertKit/Views/AlertAppleMusic17View.swift | 1 + 2 files changed, 3 insertions(+) diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index c5df8be..9c04ca3 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -176,6 +176,8 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { public override func layoutSubviews() { super.layoutSubviews() + + guard self.transform == .identity else { return } backgroundView.frame = self.bounds if let iconView = self.iconView { diff --git a/Sources/AlertKit/Views/AlertAppleMusic17View.swift b/Sources/AlertKit/Views/AlertAppleMusic17View.swift index 968052b..86d4611 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic17View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic17View.swift @@ -182,6 +182,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { public override func layoutSubviews() { super.layoutSubviews() + guard self.transform == .identity else { return } backgroundView.frame = self.bounds layout(maxWidth: frame.width) } From 3d35de60ad26aab58395ebecdd63b533546862ed Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Wed, 8 Nov 2023 18:16:43 +0300 Subject: [PATCH 11/16] Fixed crash when tap for alert. --- README.md | 12 +++++++----- SPAlert.podspec | 2 +- Sources/AlertKit/AlertKitAPI.swift | 16 +++++++++------- .../AlertKit/Views/AlertAppleMusic16View.swift | 13 ++++++++++--- .../AlertKit/Views/AlertAppleMusic17View.swift | 15 +++++++++++---- .../Views/AlertViewInternalDismissProtocol.swift | 6 ++++++ Sources/AlertKit/Views/AlertViewProtocol.swift | 2 +- 7 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 Sources/AlertKit/Views/AlertViewInternalDismissProtocol.swift diff --git a/README.md b/README.md index 8540c9e..287dedb 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ or adding it to the `dependencies` of your `Package.swift`: ```swift dependencies: [ - .package(url: "https://github.com/sparrowcode/AlertKit", .upToNextMajor(from: "5.1.5")) + .package(url: "https://github.com/sparrowcode/AlertKit", .upToNextMajor(from: "5.1.8")) ] ``` @@ -99,7 +99,7 @@ If you prefer not to use any of dependency managers, you can integrate manually. ## SwiftUI -You can use basic way via AlertKitAPI or call via modifier: +You can use basic way via `AlertKitAPI` or call via modifier: ```swift let alertView = AlertAppleMusic17View(title: "Hello", subtitle: nil, icon: .done) @@ -114,9 +114,10 @@ If you need customisation fonts, icon, colors or any other, make view: ```swift let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done) -// Change Font + +// change font alertView.titleLabel.font = UIFont.systemFont(ofSize: 21) -// Change Color +// change color alertView.titleLabel.textColor = .white ``` @@ -126,8 +127,9 @@ You can present and dismiss alerts manually via view. ```swift let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done) -alertView.present(on: self) +// present +alertView.present(on: self) // and dismiss alertView.dismiss() ``` diff --git a/SPAlert.podspec b/SPAlert.podspec index a452884..9378b4e 100644 --- a/SPAlert.podspec +++ b/SPAlert.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'SPAlert' - s.version = '5.1.6' + s.version = '5.1.8' s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.' s.homepage = 'https://github.com/sparrowcode/AlertKit' s.source = { :git => 'https://github.com/sparrowcode/AlertKit.git', :tag => s.version } diff --git a/Sources/AlertKit/AlertKitAPI.swift b/Sources/AlertKit/AlertKitAPI.swift index e6218aa..52d9da3 100644 --- a/Sources/AlertKit/AlertKitAPI.swift +++ b/Sources/AlertKit/AlertKitAPI.swift @@ -26,13 +26,16 @@ public enum AlertKitAPI { } } + /** + Call only with this one `completion`. Internal ones is canceled. + */ public static func dismissAllAlerts(completion: (() -> Void)? = nil) { - var alertViews: [AlertViewProtocol] = [] + var alertViews: [AlertViewInternalDismissProtocol] = [] for window in UIApplication.shared.windows { for view in window.subviews { - if let view = view as? AlertViewProtocol { + if let view = view as? AlertViewInternalDismissProtocol { alertViews.append(view) } } @@ -43,14 +46,13 @@ public enum AlertKitAPI { } else { for (index, view) in alertViews.enumerated() { if index == .zero { - view.dismiss(completion: completion) + view.dismiss(customCompletion: { + completion?() + }) } else { - view.dismiss(completion: nil) + view.dismiss(customCompletion: nil) } } - alertViews.first?.dismiss { - completion?() - } } } } diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index 9c04ca3..d447d8b 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -23,6 +23,8 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { fileprivate var presentDismissDuration: TimeInterval = 0.2 fileprivate var presentDismissScale: CGFloat = 0.8 + fileprivate var completion: (()->Void)? = nil + private lazy var backgroundView: UIVisualEffectView = { let view: UIVisualEffectView = { #if !os(tvOS) @@ -124,6 +126,7 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { open func present(on view: UIView, completion: (()->Void)? = nil) { self.viewForPresent = view + self.completion = completion viewForPresent?.addSubview(self) guard let viewForPresent = viewForPresent else { return } @@ -155,20 +158,24 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) { // If dismiss manually no need call original completion. if self.alpha != 0 { - self.dismiss(completion: completion) + self.dismiss() } } } }) } - @objc open func dismiss(completion: (()->Void)? = nil) { + @objc open func dismiss() { + self.dismiss(customCompletion: self.completion) + } + + func dismiss(customCompletion: (()->Void)? = nil) { UIView.animate(withDuration: presentDismissDuration, animations: { self.alpha = 0 self.transform = self.transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale) }, completion: { [weak self] finished in self?.removeFromSuperview() - completion?() + customCompletion?() }) } diff --git a/Sources/AlertKit/Views/AlertAppleMusic17View.swift b/Sources/AlertKit/Views/AlertAppleMusic17View.swift index 86d4611..f965198 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic17View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic17View.swift @@ -2,7 +2,7 @@ import UIKit import SwiftUI @available(iOS 13, visionOS 1, *) -public class AlertAppleMusic17View: UIView, AlertViewProtocol { +public class AlertAppleMusic17View: UIView, AlertViewProtocol, AlertViewInternalDismissProtocol { open var dismissByTap: Bool = true open var dismissInTime: Bool = true @@ -28,6 +28,8 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { fileprivate var presentDismissDuration: TimeInterval = 0.2 fileprivate var presentDismissScale: CGFloat = 0.8 + fileprivate var completion: (()->Void)? = nil + private lazy var backgroundView: UIView = { #if os(visionOS) let swiftUIView = VisionGlassBackgroundView(cornerRadius: 12) @@ -126,6 +128,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { open func present(on view: UIView, completion: (()->Void)? = nil) { self.viewForPresent = view + self.completion = completion viewForPresent?.addSubview(self) guard let viewForPresent = viewForPresent else { return } @@ -163,20 +166,24 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) { // If dismiss manually no need call original completion. if self.alpha != 0 { - self.dismiss(completion: completion) + self.dismiss() } } } }) } - @objc open func dismiss(completion: (()->Void)? = nil) { + @objc open func dismiss() { + self.dismiss(customCompletion: self.completion) + } + + func dismiss(customCompletion: (()->Void)? = nil) { UIView.animate(withDuration: presentDismissDuration, animations: { self.alpha = 0 self.transform = self.transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale) }, completion: { [weak self] finished in self?.removeFromSuperview() - completion?() + customCompletion?() }) } diff --git a/Sources/AlertKit/Views/AlertViewInternalDismissProtocol.swift b/Sources/AlertKit/Views/AlertViewInternalDismissProtocol.swift new file mode 100644 index 0000000..86d5052 --- /dev/null +++ b/Sources/AlertKit/Views/AlertViewInternalDismissProtocol.swift @@ -0,0 +1,6 @@ +import UIKit + +protocol AlertViewInternalDismissProtocol { + + func dismiss(customCompletion: (()->Void)?) +} diff --git a/Sources/AlertKit/Views/AlertViewProtocol.swift b/Sources/AlertKit/Views/AlertViewProtocol.swift index 19d1e6c..83b04cd 100644 --- a/Sources/AlertKit/Views/AlertViewProtocol.swift +++ b/Sources/AlertKit/Views/AlertViewProtocol.swift @@ -3,5 +3,5 @@ import UIKit public protocol AlertViewProtocol { func present(on view: UIView, completion: (()->Void)?) - func dismiss(completion: (()->Void)?) + func dismiss() } From 8150d81958e1478adca2fb00e4930aa2a8e2bfdb Mon Sep 17 00:00:00 2001 From: Vladislav Shakhray Date: Tue, 14 Nov 2023 23:26:14 +0000 Subject: [PATCH 12/16] Add Captionista to apps-using --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 287dedb..e423103 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ AlertKitAPI.dismissAllAlerts() +

If you use a `AlertKit`, add your app via Pull Request. From 23e812f8a893202fc4c436193a740a79fd118bd4 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Wed, 15 Nov 2023 17:18:46 +0300 Subject: [PATCH 13/16] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e423103..ab0ac8c 100644 --- a/README.md +++ b/README.md @@ -143,15 +143,15 @@ AlertKitAPI.dismissAllAlerts() ## Apps Using

- - - - - - - - - + + + + + + + + +

If you use a `AlertKit`, add your app via Pull Request. From fc1ce7a53ee2eb3f375f1b05e8d283ecf8e37fe1 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Thu, 30 Nov 2023 15:28:29 +0300 Subject: [PATCH 14/16] Update README.md --- README.md | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ab0ac8c..d6b6bda 100644 --- a/README.md +++ b/README.md @@ -26,23 +26,11 @@ public enum AlertViewStyle { } ``` -### Community +### iOS Dev Community

- - - - - - - - - - - - - - + + From 448c7f4fed474cfe769fd63f74da35d5539fe12e Mon Sep 17 00:00:00 2001 From: Alpay Calalli Date: Thu, 11 Apr 2024 12:07:15 +0400 Subject: [PATCH 15/16] Made AlertView's init more readable. --- Sources/AlertKit/Views/AlertAppleMusic16View.swift | 2 +- Sources/AlertKit/Views/AlertAppleMusic17View.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/AlertKit/Views/AlertAppleMusic16View.swift b/Sources/AlertKit/Views/AlertAppleMusic16View.swift index d447d8b..b58062e 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic16View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic16View.swift @@ -41,7 +41,7 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol { return view }() - public init(title: String?, subtitle: String?, icon: AlertIcon?) { + public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil) { if let title = title { let label = UILabel() diff --git a/Sources/AlertKit/Views/AlertAppleMusic17View.swift b/Sources/AlertKit/Views/AlertAppleMusic17View.swift index f965198..6215da7 100644 --- a/Sources/AlertKit/Views/AlertAppleMusic17View.swift +++ b/Sources/AlertKit/Views/AlertAppleMusic17View.swift @@ -44,7 +44,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol, AlertViewInternal #endif }() - public init(title: String?, subtitle: String?, icon: AlertIcon?) { + public init(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil) { if let title = title { let label = UILabel() From 95f5d7f5902a3ba6709faad14400ee3a16701423 Mon Sep 17 00:00:00 2001 From: Saurabh prajapati Date: Fri, 9 Aug 2024 22:56:16 +0530 Subject: [PATCH 16/16] Updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6b6bda..31c5a29 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ dependencies: [ This is an outdated way of doing things. I advise you to use [SPM](#swift-package-manager). However, I will continue to support Cocoapods for some time. -

Cocoapods Instalation +
Cocoapods Installation [CocoaPods](https://cocoapods.org) is a dependency manager. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your `Podfile`: