Skip to content

Commit abff350

Browse files
committed
Updated version and clean code.
1 parent 739c766 commit abff350

File tree

5 files changed

+85
-68
lines changed

5 files changed

+85
-68
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPAlert
22

3-
**Popup from Apple Music & Feedback in AppStore**. Contains `Done`, `Heart`, `Error` and other presets. Supports Dark Mode. I tried to recreate Apple's alerts as much as possible. You can find these alerts in the AppStore after feedback and after you add a song to your library in Apple Music.
3+
**Popup from Apple Music & Feedback in AppStore**. Contains `Done`, `Heart`, `Error` and other presets. Supports Dark Mode. I tried to recreate Apple's alerts as much as possible. You can find these alerts in the AppStore after feedback and after you add a song to your library in Apple Music. Support `SwiftUI`.
44

55
<p float="left">
66
<img src="https://github.com/ivanvorobei/SPAlert/blob/main/Assets/Readme/Animatable/Done.gif" width="230">
@@ -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+
- [SwiftUI](#swiftui)
4445
- [Other Projects](#other-projects)
4546
- [Russian Community](#russian-community)
4647

@@ -132,22 +133,20 @@ You can remove duration and completion, its have default values.
132133

133134
### SwiftUI
134135

135-
Use like system alert:
136-
137-
* only show message tips
136+
Use like system alert only show message tips:
138137

139138
```swift
140139
Button("Show alert") {
141140
showAlert = true
142-
}.alert(isPresent: $showAlert, message: "this is message only")
141+
}.spAlert(isPresent: $showAlert, message: "this is message only")
143142
```
144143

145-
* show message, title, image and other configuration
144+
or show message, title, image and other configuration:
146145

147146
```swift
148147
Button("Show alert") {
149148
showAlert = true
150-
}.alert(isPresent: $showAlert,
149+
}.spAlert(isPresent: $showAlert,
151150
title: "Alert title",
152151
message: "Alert message",
153152
duration: 2.0,

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.0.9'
4+
s.version = '3.1.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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
// Thanks @HonQii for PR!
23+
24+
import SwiftUI
25+
26+
@available(iOS 13.0, *)
27+
extension View {
28+
29+
public func spAlert(
30+
isPresent: Binding<Bool>,
31+
alertView: SPAlertView,
32+
duration: TimeInterval = 2.0,
33+
haptic: SPAlertHaptic = .none
34+
) -> some View {
35+
if isPresent.wrappedValue {
36+
let alertCompletion = alertView.completion
37+
let alertDismiss = {
38+
isPresent.wrappedValue = false
39+
alertCompletion?()
40+
}
41+
alertView.present(duration: duration, haptic: haptic, completion: alertDismiss)
42+
}
43+
return self
44+
}
45+
46+
public func spAlert(isPresent: Binding<Bool>,
47+
title: String = "",
48+
message: String? = nil,
49+
duration: TimeInterval = 2.0,
50+
dismissOnTap: Bool = true,
51+
preset: SPAlertIconPreset = .done,
52+
haptic: SPAlertHaptic = .none,
53+
layout: SPAlertLayout? = nil,
54+
completion: (()-> Void)? = nil
55+
) -> some View {
56+
let alertView = SPAlertView(title: title, message: message, preset: preset)
57+
alertView.dismissByTap = dismissOnTap
58+
alertView.layout = layout ?? SPAlertLayout(for: preset)
59+
alertView.completion = completion
60+
61+
return spAlert(isPresent: isPresent, alertView: alertView, duration: duration, haptic: haptic)
62+
}
63+
64+
public func spAlert(isPresent: Binding<Bool>,
65+
message: String,
66+
duration: TimeInterval = 2.0,
67+
dismissOnTap: Bool = true,
68+
haptic: SPAlertHaptic = .none,
69+
completion: (()-> Void)? = nil
70+
) -> some View {
71+
72+
let alertView = SPAlertView(message: message)
73+
alertView.dismissByTap = dismissOnTap
74+
alertView.completion = completion
75+
76+
return spAlert(isPresent: isPresent, alertView: alertView, duration: duration, haptic: haptic)
77+
}
78+
}

Sources/SPAlert/SwiftUI/SwiftUIAlert.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)