Skip to content

Commit c3b9d1e

Browse files
committed
Update readme. Add docs.
1 parent 83fd9db commit c3b9d1e

File tree

11 files changed

+140
-29
lines changed

11 files changed

+140
-29
lines changed

Example iOS/App/AppDelegate.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ class AppDelegate: SPAppWindowDelegate {
2727

2828
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2929
let rootController = PresetsController().wrapToNavigationController(prefersLargeTitles: false)
30-
makeKeyAndVisible(rootController)
30+
makeKeyAndVisible(rootController, tint: .systemBlue)
3131
return true
32-
33-
let alertView = SPAlertView(title: "Complete", preset: .done)
34-
alertView.present(duration: 1.5, haptic: .success, completion: nil)
35-
36-
alertView.layout.iconSize = .init(width: 24, height: 24)
37-
alertView.layout.margins.top = 12
38-
alertView.layout.spaceBetweenIconAndTitle = 8
3932
}
4033
}

Example iOS/Controllers/PresetsController.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
122
import UIKit
223
import SparrowKit
324
import SPDiffable
@@ -39,7 +60,7 @@ class PresetsController: SPDiffableTableController {
3960
.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
4061
.init(systemItem: .play, primaryAction: .init(handler: { [weak self] (action) in
4162
guard let preset = self?.currentPreset else { return }
42-
SPAlert.present(title: preset.title, message: preset.message, preset: preset.preset, completion: nil)
63+
SPAlert.present(title: preset.title, message: preset.message, preset: preset.preset, haptic: preset.haptic, completion: nil)
4364
}), menu: nil),
4465
.init(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
4566
]
@@ -53,25 +74,29 @@ class PresetsController: SPDiffableTableController {
5374
name: "Done",
5475
title: "Added to Library",
5576
message: nil,
56-
preset: .done
77+
preset: .done,
78+
haptic: .success
5779
),
5880
AlertPreset(
5981
name: "Error",
6082
title: "Oops",
6183
message: "Please try again later",
62-
preset: .error
84+
preset: .error,
85+
haptic: .error
6386
),
6487
AlertPreset(
6588
name: "Heart",
6689
title: "Love",
6790
message: "We'll recommend more like this for you",
68-
preset: .heart
91+
preset: .heart,
92+
haptic: .success
6993
),
7094
AlertPreset(
7195
name: "Custom Image",
7296
title: "Custom Image",
7397
message: "Passed UIImage object for preset with style custom.",
74-
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!)
98+
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!),
99+
haptic: .success
75100
),
76101
]
77102
}

Example iOS/Models/AlertPreset.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei ([email protected])
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
122
import UIKit
223

24+
/**
25+
Example wrapper model.
26+
*/
327
struct AlertPreset {
428

529
var name: String
630
var title: String
731
var message: String?
832
var preset: SPAlertIconPreset
33+
var haptic: SPAlertHaptic
934

1035
var id: String {
1136
return name

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ Simplifies working with animated changes in table and collections. Apple's diffa
163163

164164
В телеграм-канале [Код Воробья](https://ivanvorobei.by/sparrowcode/telegram) пишу о iOS разработке. Видео-туториалы выклыдываю на [YouTube](https://ivanvorobei.by/youtube):
165165

166-
[![Tutorials on YouTube](https://cdn.ivanvorobei.by/github/readme/youtube-preview.jpg)](https://sparrowcode.by/youtube)
166+
[![Tutorials on YouTube](https://cdn.ivanvorobei.by/github/readme/youtube-preview.jpg)](https://ivanvorobei.by/youtube)

Sources/SPAlert/Models/SPAlertIconAnimatable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121

2222
import UIKit
2323

24+
/**
25+
Protocol for animatable views.
26+
*/
2427
public protocol SPAlertIconAnimatable {
2528

29+
/**
30+
Shoud call when need start animation.
31+
*/
2632
func animate()
2733
}

Sources/SPAlert/Models/SPAlertLayout.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@
2121

2222
import UIKit
2323

24+
/**
25+
Layout model for alert view.
26+
*/
2427
open class SPAlertLayout {
2528

29+
/**
30+
Icon size.
31+
*/
2632
var iconSize: CGSize
33+
34+
/**
35+
Alert margings for each side.
36+
*/
2737
var margins: UIEdgeInsets
38+
39+
/**
40+
Space between icon and title if both available.
41+
*/
2842
var spaceBetweenIconAndTitle: CGFloat
2943

3044
init(iconSize: CGSize, margins: UIEdgeInsets, spaceBetweenIconAndTitle: CGFloat) {

Sources/SPAlert/SPAlert.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,33 @@
2121

2222
import UIKit
2323

24-
/*
25-
TODO:
26-
1. Will add dimiss mode with hide all previus alerts.
27-
And method with competion for it call manually.
28-
29-
2. Colorise for icon.
24+
/**
25+
Acess level. Here you get ready-use methods.
26+
Recomended use it.
3027
*/
3128
public enum SPAlert {
3229

33-
public static func present(title: String, message: String? = nil, preset: SPAlertIconPreset, completion: (() -> Void)? = nil) {
30+
/**
31+
Present alert with preset and haptic.
32+
33+
- parameter title: Title text in alert.
34+
- parameter message: Subtitle text in alert. Optional.
35+
- parameter preset: Icon ready-use style or custom image.
36+
- parameter haptic: Haptic response with present. Default is `.success`.
37+
- parameter completion: Will call with dismiss alert.
38+
*/
39+
public static func present(title: String, message: String? = nil, preset: SPAlertIconPreset, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
3440
let alertView = SPAlertView(title: title, message: message, preset: preset)
35-
alertView.present(completion: completion)
41+
alertView.present(haptic: haptic, completion: completion)
3642
}
3743

44+
/**
45+
Show only message, without title and icon.
46+
47+
- parameter message: Title text.
48+
- parameter haptic: Haptic response with present. Default is `.success`.
49+
- parameter completion: Will call with dismiss alert.
50+
*/
3851
public static func present(message: String, haptic: SPAlertHaptic, completion: (() -> Void)? = nil) {
3952
let alertView = SPAlertView(message: message)
4053
alertView.present(haptic: haptic, completion: completion)

Sources/SPAlert/SPAlertIconPreset.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
import UIKit
2323

24+
/**
25+
Represent icon wrapper.
26+
Included default styles and can be custom image.
27+
*/
2428
public enum SPAlertIconPreset: CaseIterable {
2529

2630
case done
@@ -36,6 +40,7 @@ public enum SPAlertIconPreset: CaseIterable {
3640
}
3741
}
3842

43+
// Get view by preset.
3944
public extension SPAlertIconPreset {
4045

4146
func createView() -> UIView {
@@ -51,6 +56,7 @@ public extension SPAlertIconPreset {
5156
}
5257
}
5358

59+
// Get layout by preset.
5460
public extension SPAlertLayout {
5561

5662
convenience init() {

Sources/SPAlert/SPAlertView.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,27 @@
2121

2222
import UIKit
2323

24+
/**
25+
Main view. Can be customisable if need.
26+
27+
For change duration, check method `present` and pass duration and other specific property if need customise.
28+
29+
Here available set window on which shoud be present.
30+
If you have some windows, you shoud configure it. Check property `presentWindow`.
31+
32+
For disable dismiss by tap, check property `.dismissByTap`.
33+
34+
Recomended call `SPAlert` and choose style func.
35+
*/
2436
open class SPAlertView: UIView {
2537

2638
// MARK: - Views
2739

28-
private var titleLabel: UILabel?
40+
open var titleLabel: UILabel?
2941

30-
private var subtitleLabel: UILabel?
42+
open var subtitleLabel: UILabel?
3143

32-
private var iconView: UIView?
44+
open var iconView: UIView?
3345

3446
private lazy var backgroundView: UIVisualEffectView = {
3547
let view: UIVisualEffectView = {
@@ -106,7 +118,7 @@ open class SPAlertView: UIView {
106118
addSubview(view)
107119
}
108120

109-
func commonInit() {
121+
private func commonInit() {
110122
preservesSuperviewLayoutMargins = false
111123
insetsLayoutMarginsFromSafeArea = false
112124
layer.masksToBounds = true

Sources/SPAlert/Services/SPAlertHaptic.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
import UIKit
2323

24+
/**
25+
Wrapper of haptic styles.
26+
*/
2427
public enum SPAlertHaptic {
2528

2629
case success

0 commit comments

Comments
 (0)