Skip to content

Commit 1cdfeda

Browse files
committed
Added spinner preset.
1 parent 9efef20 commit 1cdfeda

File tree

12 files changed

+127
-20
lines changed

12 files changed

+127
-20
lines changed

Example App/iOS Example/Controllers/PresetsController.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,35 @@ class PresetsController: SPDiffableTableController {
7171

7272
fileprivate var presets: [AlertPresetModel] {
7373
return [
74-
AlertPresetModel(
74+
.init(
7575
name: "Done",
7676
title: "Added to Library",
7777
message: nil,
7878
preset: .done
7979
),
80-
AlertPresetModel(
80+
.init(
8181
name: "Error",
8282
title: "Oops",
8383
message: "Please try again later",
8484
preset: .error
8585
),
86-
AlertPresetModel(
86+
.init(
8787
name: "Heart",
8888
title: "Love",
8989
message: "We'll recommend more like this for you",
9090
preset: .heart
9191
),
92-
AlertPresetModel(
92+
.init(
93+
name: "Spinner (Loading)",
94+
title: "Please, wait",
95+
message: "It take some time",
96+
preset: .spinner
97+
),
98+
.init(
9399
name: "Custom Image",
94100
title: "Custom Image",
95101
message: "Passed UIImage object for preset with style custom.",
96-
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!)
102+
preset: .custom(UIImage.init(systemName: "pencil.and.outline")!.withRenderingMode(.alwaysOriginal))
97103
),
98104
]
99105
}

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ If you like the project, don't forget to `put star ★`<br>Check out my other li
4545
- [Layout](#layout)
4646
- [Dismiss by Tap](#dismiss-by-tap)
4747
- [Haptic](#haptic)
48-
- [Shared Configuration](#shared-configuration)
48+
- [Spinner](#spinner)
49+
- [Shared Appearance](#shared-appearance)
4950
- [SwiftUI](#swiftui)
5051
- [Сontribution](#сontribution)
5152
- [Other Projects](#other-projects)
@@ -107,9 +108,12 @@ For change duration of present time, create alert view and call `present` method
107108

108109
```swift
109110
let alertView = SPAlertView(title: "Complete", preset: .done)
110-
alertView.present(duration: 3)
111+
alertView.duration = 4
112+
alertView.present()
111113
```
112114

115+
If you don't want to dimiss alert in time, set `dismissInTime` to `false`. After it `duration` property will be ignored.
116+
113117
### Layout
114118

115119
For customise layout and margins, use `layout` property. You can manage margins for each side, icon size and space between image and titles:
@@ -137,7 +141,19 @@ alertView.present(duration: 1.5, haptic: .success, completion: nil)
137141

138142
You can remove duration and completion, its have default values.
139143

140-
### Shared Configuration
144+
### Spinner
145+
146+
I added preset `.spinner`, for use it simple call this:
147+
148+
```swift
149+
let
150+
let alertView = SPAlertView(title: "Please, wait", preset: .spinner)
151+
alertView.present()
152+
```
153+
154+
By default for this preset `dismissInTime` disabled and need manually dismiss alert.
155+
156+
### Shared Appearance
141157

142158
Also you can change some default values for alerts. For example you can change default duration and corner radius for alert with next code:
143159

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.4.1'
4+
s.version = '3.5.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 }

Sources/SPAlert/Extensions/SwiftUIExtension.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extension View {
3939
isPresent.wrappedValue = false
4040
alertCompletion?()
4141
}
42-
alertView.present(duration: duration, haptic: haptic, completion: alertDismiss)
42+
alertView.duration = duration
43+
alertView.present(haptic: haptic, completion: alertDismiss)
4344
}
4445
return self
4546
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
class SPAlertSpinnerView: UIView {
25+
26+
let activityIndicatorView: UIActivityIndicatorView = {
27+
if #available(iOS 13.0, *) {
28+
return UIActivityIndicatorView(style: .large)
29+
} else {
30+
return UIActivityIndicatorView()
31+
}
32+
}()
33+
34+
init() {
35+
super.init(frame: .zero)
36+
self.backgroundColor = .clear
37+
addSubview(activityIndicatorView)
38+
activityIndicatorView.startAnimating()
39+
}
40+
41+
required init?(coder aDecoder: NSCoder) {
42+
fatalError("init(coder:) has not been implemented")
43+
}
44+
45+
override func layoutSubviews() {
46+
super.layoutSubviews()
47+
activityIndicatorView.sizeToFit()
48+
activityIndicatorView.center = .init(x: frame.width / 2, y: frame.height / 2)
49+
}
50+
51+
}

Sources/SPAlert/SPAlert.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public enum SPAlert {
5252
*/
5353
public static func present(title: String, message: String? = nil, preset: SPAlertIconPreset, completion: (() -> Void)? = nil) {
5454
let alertView = SPAlertView(title: title, message: message, preset: preset)
55-
let haptic = preset.getHaptic()
56-
alertView.present(haptic: haptic, completion: completion)
55+
alertView.present(haptic: preset.haptic, completion: completion)
5756
}
5857

5958
/**

0 commit comments

Comments
 (0)