From 5fd3e2923d26f0f0b40f0e6c10fca458a61a73c4 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Mon, 17 Jan 2022 13:51:36 +0300 Subject: [PATCH] Updated example app. --- Example App/SPAlert.xcodeproj/project.pbxproj | 4 +-- .../xcshareddata/swiftpm/Package.resolved | 8 ++--- .../Controllers/PresetsController.swift | 29 +++++++++++-------- SPAlert.podspec | 2 +- Sources/SPAlert/SPAlert.swift | 10 ++++--- Sources/SPAlert/SPAlertIconPreset.swift | 2 +- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Example App/SPAlert.xcodeproj/project.pbxproj b/Example App/SPAlert.xcodeproj/project.pbxproj index 1e62417..0cac476 100644 --- a/Example App/SPAlert.xcodeproj/project.pbxproj +++ b/Example App/SPAlert.xcodeproj/project.pbxproj @@ -379,7 +379,7 @@ repositoryURL = "https://github.com/ivanvorobei/SparrowKit"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 3.0.7; + minimumVersion = 3.5.0; }; }; F43A587526564C7D009098ED /* XCRemoteSwiftPackageReference "SPDiffable" */ = { @@ -387,7 +387,7 @@ repositoryURL = "https://github.com/ivanvorobei/SPDiffable"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 1.2.2; + minimumVersion = 4.0.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Example App/SPAlert.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example App/SPAlert.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 8f1d01e..afc95fd 100644 --- a/Example App/SPAlert.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example App/SPAlert.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/ivanvorobei/SparrowKit", "state": { "branch": null, - "revision": "d1a2d489417f98620558da08ddcf44a9d53e58f3", - "version": "3.2.0" + "revision": "ec3da50d713713d43b26a3e191f33f9930fd0e82", + "version": "3.5.0" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/ivanvorobei/SPDiffable", "state": { "branch": null, - "revision": "884198fb29a339156b824483bc09e2b488d27e28", - "version": "1.4.1" + "revision": "d09a126517371bc34080d0f2dad70ffd724f862e", + "version": "4.0.0" } } ] diff --git a/Example App/iOS Example/Controllers/PresetsController.swift b/Example App/iOS Example/Controllers/PresetsController.swift index 11a8cf1..580f717 100644 --- a/Example App/iOS Example/Controllers/PresetsController.swift +++ b/Example App/iOS Example/Controllers/PresetsController.swift @@ -43,7 +43,7 @@ class PresetsController: SPDiffableTableController { navigationItem.title = "SPAlert Presets" currentPreset = presets.first! - setCellProviders(SPDiffableTableCellProviders.default, sections: content) + configureDiffable(sections: content, cellProviders: SPDiffableTableDataSource.CellProvider.default) navigationController?.isToolbarHidden = false toolbarItems = [ @@ -61,7 +61,19 @@ class PresetsController: SPDiffableTableController { .init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), .init(systemItem: .play, primaryAction: .init(handler: { [weak self] (action) in guard let preset = self?.currentPreset else { return } - SPAlert.present(title: preset.title, message: preset.message, preset: preset.preset, completion: nil) + SPAlert.present( + title: preset.title, + message: preset.message, + preset: preset.preset, + completion: nil + ) + + if preset.preset == SPAlertIconPreset.spinner { + delay(2, closure: { + SPAlert.dismiss() + }) + } + }), menu: nil), .init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), ] @@ -107,15 +119,8 @@ class PresetsController: SPDiffableTableController { // MARK: - Diffable var currentPreset: AlertPresetModel? { - willSet { - guard let id = self.currentPreset?.id else { return } - let cell = diffableDataSource?.cell(UITableViewCell.self, for: id) - cell?.accessoryType = .none - } didSet { - guard let id = self.currentPreset?.id else { return } - let cell = diffableDataSource?.cell(UITableViewCell.self, for: id) - cell?.accessoryType = .checkmark + self.diffableDataSource?.set(content, animated: false) } } @@ -124,13 +129,13 @@ class PresetsController: SPDiffableTableController { return SPDiffableTableRow( text: preset.name, accessoryType: (preset.id == currentPreset?.id) ? .checkmark : .none, - selectionStyle: .none) { [weak self] _ in + selectionStyle: .none) { [weak self] _,_ in guard let self = self else { return } self.currentPreset = preset } } return [ - SPDiffableSection(identifier: "presets", header: nil, footer: nil, items: items) + SPDiffableSection(id: "presets", header: nil, footer: nil, items: items) ] } } diff --git a/SPAlert.podspec b/SPAlert.podspec index 1440dfe..eb58ccc 100644 --- a/SPAlert.podspec +++ b/SPAlert.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'SPAlert' - s.version = '4.1.0' + s.version = '4.2.0' s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.' s.homepage = 'https://github.com/ivanvorobei/SPAlert' s.source = { :git => 'https://github.com/ivanvorobei/SPAlert.git', :tag => s.version } diff --git a/Sources/SPAlert/SPAlert.swift b/Sources/SPAlert/SPAlert.swift index e6579bf..ffba5cf 100644 --- a/Sources/SPAlert/SPAlert.swift +++ b/Sources/SPAlert/SPAlert.swift @@ -83,10 +83,12 @@ public enum SPAlert { public static func dismiss() { if #available(iOS 13.0, *) { for scene in UIApplication.shared.connectedScenes { - if let windowScene = scene as? UIWindowSceneDelegate { - for view in windowScene.window??.subviews ?? [] { - if let alertView = view as? SPAlertView { - alertView.dismiss() + if let windowScene = scene as? UIWindowScene { + windowScene.windows.forEach { window in + for view in window.subviews { + if let alertView = view as? SPAlertView { + alertView.dismiss() + } } } } diff --git a/Sources/SPAlert/SPAlertIconPreset.swift b/Sources/SPAlert/SPAlertIconPreset.swift index 4c93e5c..a12db4a 100644 --- a/Sources/SPAlert/SPAlertIconPreset.swift +++ b/Sources/SPAlert/SPAlertIconPreset.swift @@ -25,7 +25,7 @@ import UIKit SPAlert: Represent icon wrapper. Included default styles and can be custom image. */ -public enum SPAlertIconPreset { +public enum SPAlertIconPreset: Equatable { case done case error