Skip to content

Commit

Permalink
Added Configuration interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvorobei committed Jun 19, 2021
1 parent 79ad8c5 commit 9303ef6
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
Binary file not shown.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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)
- [Shared Configuration](#shared-configuration)
- [SwiftUI](#swiftui)
- [Other Projects](#other-projects)
- [Russian Community](#russian-community)
Expand Down Expand Up @@ -131,6 +132,17 @@ alertView.present(duration: 1.5, haptic: .success, completion: nil)

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

### Shared Configuration

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

```swift
SPAlertConfiguration.duration = 2
SPAlertConfiguration.cornerRadius = 12
```

It will apply for all alerts. Shoud set configuration before present any alerts.

## SwiftUI

Use like system alert only show message tips:
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.1.1'
s.version = '3.2.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
59 changes: 59 additions & 0 deletions Sources/SPAlert/SPAlertConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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.

import UIKit

/**
SPAlert: Configuration interface.

Use this for change default values. For example you want change default duration of alerts,
set property `duration` to specific value.
*/
public class SPAlertConfiguration {

// MARK: - Public

/**
SPAlert: Change default corner radius for alert views.
*/
public static var cornerRadius: CGFloat {
get { shared.cornerRadius }
set { shared.cornerRadius = newValue }
}

/**
SPAlert: Change visible duration for alerts.
*/
public static var duration: TimeInterval {
get { shared.duration }
set { shared.duration = newValue }
}

// MARK: - Internal

private var cornerRadius: CGFloat = 8
private var duration: TimeInterval = 1.5

// MARK: - Singltone

private static let shared = SPAlertConfiguration()
private init() {}
}
4 changes: 2 additions & 2 deletions Sources/SPAlert/SPAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ open class SPAlertView: UIView {
insetsLayoutMarginsFromSafeArea = false
}
layer.masksToBounds = true
layer.cornerRadius = 8
layer.cornerRadius = SPAlertConfiguration.cornerRadius ?? 8
backgroundColor = .clear
addSubview(backgroundView)

Expand Down Expand Up @@ -156,7 +156,7 @@ open class SPAlertView: UIView {
}
}

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

if self.presentWindow == nil {
self.presentWindow = UIApplication.shared.keyWindow
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Here provided ideas or features which will be implemented soon.

// Empty
- Mode animatable views.

0 comments on commit 9303ef6

Please sign in to comment.