Skip to content

Commit 9303ef6

Browse files
committed
Added Configuration interface.
1 parent 79ad8c5 commit 9303ef6

File tree

6 files changed

+75
-4
lines changed

6 files changed

+75
-4
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ If you like the project, don't forget to `put star ★` and follow me on GitHub:
4141
- [Layout](#layout)
4242
- [Dismiss by Tap](#dismiss-by-tap)
4343
- [Haptic](#haptic)
44+
- [Shared Configuration](#shared-configuration)
4445
- [SwiftUI](#swiftui)
4546
- [Other Projects](#other-projects)
4647
- [Russian Community](#russian-community)
@@ -131,6 +132,17 @@ alertView.present(duration: 1.5, haptic: .success, completion: nil)
131132

132133
You can remove duration and completion, its have default values.
133134

135+
### Shared Configuration
136+
137+
Also you can change some default values for alerts. For example you can change default duration and corner radius for alert with next code:
138+
139+
```swift
140+
SPAlertConfiguration.duration = 2
141+
SPAlertConfiguration.cornerRadius = 12
142+
```
143+
144+
It will apply for all alerts. Shoud set configuration before present any alerts.
145+
134146
## SwiftUI
135147

136148
Use like system alert only show message tips:

SPAlert.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SPAlert'
4-
s.version = '3.1.1'
4+
s.version = '3.2.0'
55
s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.'
66
s.homepage = 'https://github.com/ivanvorobei/SPAlert'
77
s.source = { :git => 'https://github.com/ivanvorobei/SPAlert.git', :tag => s.version }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
22+
import UIKit
23+
24+
/**
25+
SPAlert: Configuration interface.
26+
27+
Use this for change default values. For example you want change default duration of alerts,
28+
set property `duration` to specific value.
29+
*/
30+
public class SPAlertConfiguration {
31+
32+
// MARK: - Public
33+
34+
/**
35+
SPAlert: Change default corner radius for alert views.
36+
*/
37+
public static var cornerRadius: CGFloat {
38+
get { shared.cornerRadius }
39+
set { shared.cornerRadius = newValue }
40+
}
41+
42+
/**
43+
SPAlert: Change visible duration for alerts.
44+
*/
45+
public static var duration: TimeInterval {
46+
get { shared.duration }
47+
set { shared.duration = newValue }
48+
}
49+
50+
// MARK: - Internal
51+
52+
private var cornerRadius: CGFloat = 8
53+
private var duration: TimeInterval = 1.5
54+
55+
// MARK: - Singltone
56+
57+
private static let shared = SPAlertConfiguration()
58+
private init() {}
59+
}

Sources/SPAlert/SPAlertView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class SPAlertView: UIView {
9191
insetsLayoutMarginsFromSafeArea = false
9292
}
9393
layer.masksToBounds = true
94-
layer.cornerRadius = 8
94+
layer.cornerRadius = SPAlertConfiguration.cornerRadius ?? 8
9595
backgroundColor = .clear
9696
addSubview(backgroundView)
9797

@@ -156,7 +156,7 @@ open class SPAlertView: UIView {
156156
}
157157
}
158158

159-
open func present(duration: TimeInterval = 1.5, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
159+
open func present(duration: TimeInterval = SPAlertConfiguration.duration, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
160160

161161
if self.presentWindow == nil {
162162
self.presentWindow = UIApplication.shared.keyWindow

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
Here provided ideas or features which will be implemented soon.
44

5-
// Empty
5+
- Mode animatable views.

0 commit comments

Comments
 (0)