Skip to content

Commit

Permalink
Updated example app.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jan 17, 2022
1 parent 28ecf2a commit 5fd3e29
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Example App/SPAlert.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,15 @@
repositoryURL = "https://github.com/ivanvorobei/SparrowKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.0.7;
minimumVersion = 3.5.0;
};
};
F43A587526564C7D009098ED /* XCRemoteSwiftPackageReference "SPDiffable" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ivanvorobei/SPDiffable";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.2.2;
minimumVersion = 4.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
"repositoryURL": "https://github.com/ivanvorobei/SparrowKit",
"state": {
"branch": null,
"revision": "d1a2d489417f98620558da08ddcf44a9d53e58f3",
"version": "3.2.0"
"revision": "ec3da50d713713d43b26a3e191f33f9930fd0e82",
"version": "3.5.0"
}
},
{
"package": "SPDiffable",
"repositoryURL": "https://github.com/ivanvorobei/SPDiffable",
"state": {
"branch": null,
"revision": "884198fb29a339156b824483bc09e2b488d27e28",
"version": "1.4.1"
"revision": "d09a126517371bc34080d0f2dad70ffd724f862e",
"version": "4.0.0"
}
}
]
Expand Down
29 changes: 17 additions & 12 deletions Example App/iOS Example/Controllers/PresetsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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),
]
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
]
}
}
2 changes: 1 addition & 1 deletion SPAlert.podspec
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
10 changes: 6 additions & 4 deletions Sources/SPAlert/SPAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPAlert/SPAlertIconPreset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fd3e29

Please sign in to comment.