Skip to content

Commit afd3b41

Browse files
committed
Add docs
1 parent 5f5ea62 commit afd3b41

File tree

6 files changed

+116
-7
lines changed

6 files changed

+116
-7
lines changed

Source/SPAlert/Models/SPAlertHaptic.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@
2121

2222
import UIKit
2323

24+
/**
25+
Vibro assest. Call `impact` for run.
26+
*/
2427
public enum SPAlertHaptic {
25-
28+
2629
case success
2730
case warning
2831
case error
2932
case none
3033

34+
/**
35+
Run vibro-haptic.
36+
*/
3137
func impact() {
3238
let generator = UINotificationFeedbackGenerator()
33-
3439
switch self {
3540
case .success:
3641
generator.notificationOccurred(UINotificationFeedbackGenerator.FeedbackType.success)

Source/SPAlert/Models/SPAlertLayout.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,33 @@
2121

2222
import UIKit
2323

24+
/**
25+
Layout for alert.
26+
*/
2427
public struct SPAlertLayout {
2528

29+
/**
30+
Top space from icon to top area,
31+
*/
2632
public var topSpace: CGFloat = 43
33+
34+
/**
35+
Bottom space from titles to bottom area.
36+
*/
2737
public var bottomSpace: CGFloat = 25
38+
39+
/**
40+
Icon width.
41+
*/
2842
public var iconWidth: CGFloat = 100
43+
44+
/**
45+
Icon height.
46+
*/
2947
public var iconHeight: CGFloat = 100
48+
49+
/**
50+
Bottom space from icon to titles.
51+
*/
3052
public var bottomIconSpace: CGFloat = 41
3153
}

Source/SPAlert/Models/SPAlertPreset.swift

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

2222
import UIKit
2323

24+
/**
25+
Defaults values, icons and vibro for ready-using presets.
26+
*/
2427
public enum SPAlertPreset {
2528

2629
case done
2730
case heart
2831
case doc
2932
case error
3033

34+
/**
35+
View for preset.
36+
*/
3137
var iconView: UIView {
3238
switch self {
3339
case .done:
@@ -41,6 +47,9 @@ public enum SPAlertPreset {
4147
}
4248
}
4349

50+
/**
51+
Layout for preset. Include spacings and icon size.
52+
*/
4453
var layout: SPAlertLayout {
4554
switch self {
4655
case .done:
@@ -78,6 +87,9 @@ public enum SPAlertPreset {
7887
}
7988
}
8089

90+
/**
91+
Default vibro. Can customize after create with preset.
92+
*/
8193
var haptic: SPAlertHaptic {
8294
switch self {
8395
case .done:

Source/SPAlert/Protocol/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 generate animatable icon.
26+
*/
2427
public protocol SPAlertIconAnimatable {
2528

29+
/**
30+
Func call when need start animate icon. Recomend using duration fewer 1. No need call manually, it function call auto.
31+
*/
2632
func animate()
2733
}

Source/SPAlert/SPAlert.swift

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

2222
import UIKit
2323

24+
/**
25+
Base class with fast presenting.
26+
*/
2427
public enum SPAlert {
2528

29+
/**
30+
Present with presets.
31+
*/
2632
public static func present(title: String, message: String? = nil, preset: SPAlertPreset) {
2733
let alertView = SPAlertView(title: title, message: message, preset: preset)
2834
alertView.present()
2935
}
3036

37+
/**
38+
Present with image.
39+
*/
3140
public static func present(title: String, message: String? = nil, image: UIImage) {
3241
let alertView = SPAlertView(title: title, message: message, image: image)
3342
alertView.present()
3443
}
3544

45+
/**
46+
Present only message, without icon.
47+
48+
- parameter haptic: Pass with vibro using with present alet.
49+
*/
3650
public static func present(message: String, haptic: SPAlertHaptic = .none) {
3751
let alertView = SPAlertView(message: message)
3852
alertView.haptic = haptic

Source/SPAlert/Views/SPAlertView.swift

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,57 @@
2121

2222
import UIKit
2323

24+
/**
25+
View which presenting. You can configure `titleLabel`, `subtitleLabel` and other. For change duration use property `duration`.
26+
Also you can configure layout & haptic. If you use preset, all configure automatically.
27+
*/
2428
open class SPAlertView: UIView {
2529

30+
/**
31+
Large top text on alert.
32+
*/
2633
private var titleLabel: UILabel? = nil
34+
35+
/**
36+
Small text on alert.
37+
*/
2738
private var subtitleLabel: UILabel? = nil
39+
40+
/**
41+
Icon view. Size for it configure in `layout` property.
42+
*/
2843
private var iconView: UIView? = nil
44+
45+
/**
46+
Blur view for background.
47+
*/
2948
private var backgroundView: UIVisualEffectView!
3049

50+
/**
51+
Duration time when alert visible.
52+
*/
3153
public var duration: TimeInterval = 1.5
54+
55+
/**
56+
Allow dismiss by tap on alert. By default it allowed.
57+
*/
3258
public var dismissByTap: Bool = true
59+
60+
/**
61+
Vibro for this alert. Default value using for presets. If you init custom. haptic not configure.
62+
*/
3363
public var haptic: SPAlertHaptic = .none
64+
65+
/**
66+
Spacing and icon size configure here. Auto configure when you using presets.
67+
*/
3468
public var layout = SPAlertLayout()
3569

70+
/**
71+
View on which present alert.
72+
*/
73+
public var keyWindow: UIView = (UIApplication.shared.keyWindow ?? UIWindow())
74+
3675
public init(title: String, message: String?, preset: SPAlertPreset) {
3776
super.init(frame: CGRect.zero)
3877
iconView = preset.iconView
@@ -117,7 +156,7 @@ open class SPAlertView: UIView {
117156
titleLabel.attributedText = NSAttributedString(string: titleLabel.text ?? "", attributes: [.paragraphStyle: style])
118157
addSubview(titleLabel)
119158
}
120-
159+
121160
if let subtitleLabel = subtitleLabel {
122161
subtitleLabel.font = UIFont.systemFont(ofSize: 16)
123162
subtitleLabel.numberOfLines = 0
@@ -138,6 +177,9 @@ open class SPAlertView: UIView {
138177

139178
// MARK: - Public
140179

180+
/**
181+
Use this method for present controller. No need pass any controller, alert appear on `keyWindow`.
182+
*/
141183
public func present() {
142184
haptic.impact()
143185
keyWindow.addSubview(self)
@@ -159,6 +201,9 @@ open class SPAlertView: UIView {
159201
})
160202
}
161203

204+
/**
205+
Use this method for force dismiss controller. By default it call automatically.
206+
*/
162207
@objc func dismiss() {
163208
UIView.animate(withDuration: 0.2, animations: {
164209
self.alpha = 0
@@ -191,12 +236,18 @@ open class SPAlertView: UIView {
191236
backgroundView.frame = bounds
192237
}
193238

239+
/**
240+
Layout labels with multi-lines.
241+
*/
194242
private func layout(_ label: UILabel, x: CGFloat, y: CGFloat, width: CGFloat) {
195243
label.frame = CGRect.init(x: x, y: y, width: width, height: 0)
196244
label.sizeToFit()
197245
label.frame = CGRect.init(x: x, y: y, width: width, height: label.frame.height)
198246
}
199247

248+
/**
249+
This menthod call when need calulate height with layout.
250+
*/
200251
private func calculateHeight() -> CGFloat {
201252
var height: CGFloat = 0
202253
if let subtitleLabel = subtitleLabel {
@@ -213,8 +264,9 @@ open class SPAlertView: UIView {
213264
return height
214265
}
215266

216-
// MARK: - Internal
217-
267+
/**
268+
Check `userInterfaceStyle` mode.
269+
*/
218270
private var isDarkMode: Bool {
219271
if #available(iOS 12.0, *) {
220272
if traitCollection.userInterfaceStyle == .dark {
@@ -226,6 +278,4 @@ open class SPAlertView: UIView {
226278
return false
227279
}
228280
}
229-
230-
public var keyWindow: UIView = (UIApplication.shared.keyWindow ?? UIWindow())
231281
}

0 commit comments

Comments
 (0)