Added source code. Added Readme preview.
This commit is contained in:
1 parent
feee1339fa
commit
73e05f7353
23 files changed
+1115
-17
No files matched your search
@@ -1,5 +1,5 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@ import SparrowKit
|
||||
class AppDelegate: SPAppWindowDelegate {
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
let rootController = RootController().wrapToNavigationController(prefersLargeTitles: false)
|
||||
let rootController = PresetsController().wrapToNavigationController(prefersLargeTitles: false)
|
||||
makeKeyAndVisible(rootController, tint: .systemBlue)
|
||||
return true
|
||||
}
|
||||
|
||||
+16
-3
@@ -1,5 +1,5 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -20,6 +20,19 @@
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
import SparrowKit
|
||||
import SPIndicator
|
||||
|
||||
class RootController: SPController {}
|
||||
/**
|
||||
Example wrapper model.
|
||||
*/
|
||||
struct IndicatorPresetModel {
|
||||
|
||||
var name: String
|
||||
var title: String
|
||||
var message: String?
|
||||
var preset: SPIndicatorIconPreset
|
||||
|
||||
var id: String {
|
||||
return name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.by)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
import SparrowKit
|
||||
import SPDiffable
|
||||
import SPIndicator
|
||||
|
||||
class PresetsController: SPDiffableTableController {
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
init() {
|
||||
super.init(style: .insetGrouped)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
navigationItem.title = "SPAlert Presets"
|
||||
|
||||
currentPreset = presets.first!
|
||||
setCellProviders(SPDiffableTableCellProviders.default, sections: content)
|
||||
|
||||
navigationController?.isToolbarHidden = false
|
||||
toolbarItems = [
|
||||
.init(image: .system("chevron.down.circle"), primaryAction: .init(handler: { (action) in
|
||||
guard let currentPreset = self.currentPreset else {
|
||||
self.currentPreset = self.presets.first
|
||||
return
|
||||
}
|
||||
guard let index = self.presets.firstIndex(where: { $0.id == currentPreset.id }) else { return }
|
||||
self.currentPreset = self.presets[safe: index + 1]
|
||||
if self.currentPreset == nil {
|
||||
self.currentPreset = self.presets.first
|
||||
}
|
||||
})),
|
||||
.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
|
||||
.init(systemItem: .play, primaryAction: .init(handler: { [weak self] (action) in
|
||||
guard let preset = self?.currentPreset else { return }
|
||||
SPIndicator.present(title: preset.title, message: preset.message, preset: preset.preset, completion: nil)
|
||||
}), menu: nil),
|
||||
.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Data
|
||||
|
||||
fileprivate var presets: [IndicatorPresetModel] {
|
||||
return [
|
||||
IndicatorPresetModel(
|
||||
name: "Done",
|
||||
title: "Done",
|
||||
message: "Animatable",
|
||||
preset: .done
|
||||
),
|
||||
IndicatorPresetModel(
|
||||
name: "Error",
|
||||
title: "Oops",
|
||||
message: "Try again",
|
||||
preset: .error
|
||||
),
|
||||
IndicatorPresetModel(
|
||||
name: "Custom Image",
|
||||
title: "Custom Image",
|
||||
message: "SFSymbols Image",
|
||||
preset: .custom(UIImage.init(systemName: "swift")!)
|
||||
),
|
||||
IndicatorPresetModel(
|
||||
name: "Specific Tint",
|
||||
title: "Specific Tint",
|
||||
message: "For any image",
|
||||
preset: .custom(UIImage.init(systemName: "sun.min.fill")!.withTintColor(.systemYellow, renderingMode: .alwaysOriginal))
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Diffable
|
||||
|
||||
var currentPreset: IndicatorPresetModel? {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
var content: [SPDiffableSection] {
|
||||
let items = presets.map { (preset) -> SPDiffableTableRow in
|
||||
return SPDiffableTableRow(
|
||||
text: preset.name,
|
||||
accessoryType: (preset.id == currentPreset?.id) ? .checkmark : .none,
|
||||
selectionStyle: .none) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
self.currentPreset = preset
|
||||
}
|
||||
}
|
||||
return [
|
||||
SPDiffableSection(identifier: "presets", header: nil, footer: nil, items: items)
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user