Skip to content

Commit

Permalink
Updated version and clean code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jun 4, 2021
1 parent 739c766 commit abff350
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 68 deletions.
Binary file not shown.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPAlert

**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.
**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`.

<p float="left">
<img src="https://github.com/ivanvorobei/SPAlert/blob/main/Assets/Readme/Animatable/Done.gif" width="230">
Expand Down Expand Up @@ -41,6 +41,7 @@ If you like the project, don't forget to `put star ★` and follow me on GitHub:
- [Layout](#layout)
- [Dismiss by Tap](#dismiss-by-tap)
- [Haptic](#haptic)
- [SwiftUI](#swiftui)
- [Other Projects](#other-projects)
- [Russian Community](#russian-community)

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

### SwiftUI

Use like system alert:

* only show message tips
Use like system alert only show message tips:

```swift
Button("Show alert") {
showAlert = true
}.alert(isPresent: $showAlert, message: "this is message only")
}.spAlert(isPresent: $showAlert, message: "this is message only")
```

* show message, title, image and other configuration
or show message, title, image and other configuration:

```swift
Button("Show alert") {
showAlert = true
}.alert(isPresent: $showAlert,
}.spAlert(isPresent: $showAlert,
title: "Alert title",
message: "Alert message",
duration: 2.0,
Expand Down
2 changes: 1 addition & 1 deletion SPAlert.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'SPAlert'
s.version = '3.0.9'
s.version = '3.1.0'
s.summary = 'Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.'
s.homepage = 'https://github.com/ivanvorobei/SPAlert'
s.source = { :git => 'https://github.com/ivanvorobei/SPAlert.git', :tag => s.version }
Expand Down
78 changes: 78 additions & 0 deletions Sources/SPAlert/Extensions/SwiftUIExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// The MIT License (MIT)
// Copyright © 2020 Ivan Vorobei ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// Thanks @HonQii for PR!

import SwiftUI

@available(iOS 13.0, *)
extension View {

public func spAlert(
isPresent: Binding<Bool>,
alertView: SPAlertView,
duration: TimeInterval = 2.0,
haptic: SPAlertHaptic = .none
) -> some View {
if isPresent.wrappedValue {
let alertCompletion = alertView.completion
let alertDismiss = {
isPresent.wrappedValue = false
alertCompletion?()
}
alertView.present(duration: duration, haptic: haptic, completion: alertDismiss)
}
return self
}

public func spAlert(isPresent: Binding<Bool>,
title: String = "",
message: String? = nil,
duration: TimeInterval = 2.0,
dismissOnTap: Bool = true,
preset: SPAlertIconPreset = .done,
haptic: SPAlertHaptic = .none,
layout: SPAlertLayout? = nil,
completion: (()-> Void)? = nil
) -> some View {
let alertView = SPAlertView(title: title, message: message, preset: preset)
alertView.dismissByTap = dismissOnTap
alertView.layout = layout ?? SPAlertLayout(for: preset)
alertView.completion = completion

return spAlert(isPresent: isPresent, alertView: alertView, duration: duration, haptic: haptic)
}

public func spAlert(isPresent: Binding<Bool>,
message: String,
duration: TimeInterval = 2.0,
dismissOnTap: Bool = true,
haptic: SPAlertHaptic = .none,
completion: (()-> Void)? = nil
) -> some View {

let alertView = SPAlertView(message: message)
alertView.dismissByTap = dismissOnTap
alertView.completion = completion

return spAlert(isPresent: isPresent, alertView: alertView, duration: duration, haptic: haptic)
}
}
60 changes: 0 additions & 60 deletions Sources/SPAlert/SwiftUI/SwiftUIAlert.swift

This file was deleted.

0 comments on commit abff350

Please sign in to comment.