Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgr-ksmt committed Jul 5, 2019
2 parents 5059fd0 + 51ac554 commit f9cbb8f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Alertift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Alertift"
s.version = "4.1"
s.version = "4.1.1"
s.summary = "UIAlertControlelr wrapper for Swift."
s.homepage = "https://github.com/sgr-ksmt/Alertift"
# s.screenshots = ""
Expand Down
4 changes: 2 additions & 2 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class ViewController: UIViewController {

private func showYesOrNoAlert() {
Alertift.alert(title: "Sample 2",message: "Do you like 🍣?")
.action(.default("Yes"), isPreferred: true) { (_, _, _) in
.action(.default("Yes"), isPreferred: true) {
Alertift.alert(message: "🍣🍣🍣")
.action(.default("Close"))
.show()
}
.action(.cancel("No")) { (_, _, _) in
.action(.cancel("No")) {
Alertift.alert(message: "😂😂😂")
.action(.destructive("Close"))
.show()
Expand Down
2 changes: 1 addition & 1 deletion Documents/how_to_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Alertift.alert(title: "Sample 1", message: "Simple alert!")

```swift
Alertift.alert(title: "Confirm", message: "Delete this post?")
.action(.destructive("Delete")) { _, _, _ in
.action(.destructive("Delete")) {
// delete post
}
.action(.cancel("Cancel"))
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awes

## Requirements
- iOS 9.0+
- Xcode 8.1+
- Swift 3.0+
- Xcode 10+
- Swift 5.0+

## Installation

Expand Down Expand Up @@ -81,9 +81,6 @@ and run `pod install`
### Manually Install
Download all `*.swift` files and put your project.

## Change log
Change log is [here](https://github.com/sgr-ksmt/Alertift/blob/master/CHANGELOG.md).

## Communication
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
Expand Down
14 changes: 11 additions & 3 deletions Sources/ActionSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
extension Alertift {
/// ActionSheet
final public class ActionSheet: AlertType, _AlertType {

public typealias Handler = (UIAlertAction, Int) -> Void

var _alertController: InnerAlertController!
Expand All @@ -35,12 +34,17 @@ extension Alertift {
}

/// Add action to alertController
public func action(_ action: Alertift.Action, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, handler: Handler?) -> Self {
return self.action(action, image: nil, handler: handler)
}

public func action(_ action: Alertift.Action, handler: ShortHandler? = nil) -> Self {
return self.action(action) { _, _ in handler?() }
}


/// Add action to alertController
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler?) -> Self {
let alertAction = buildAlertAction(action, handler:
merge(_alertController.actionHandler, handler ?? { (_, _) in })
)
Expand All @@ -52,6 +56,10 @@ extension Alertift {
_alertController.addAction(alertAction)
return self
}

public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: ShortHandler? = nil) -> Self {
return self.action(action, image: image, renderingMode: renderingMode) { _, _ in handler?() }
}

/// Add sourceView and sourceRect to **popoverPresentationController**.
///
Expand Down
23 changes: 19 additions & 4 deletions Sources/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,28 @@ extension Alertift {
buildAlertControlelr(title: title, message: message, style: .alert)
}

public func action(_ action: Alertift.Action, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, handler: Handler?) -> Self {
return self.action(action, isPreferred: false, handler: handler)
}

public func action(_ action: Alertift.Action, handler: ShortHandler? = nil) -> Self {
return self.action(action) { _, _, _ in handler?() }
}
/// Add action to Alert
///
/// - Parameters:
/// - action: Alert action.
/// - isPreferred: If you want to change this action to preferredAction, set true. Default is false.
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
public func action(_ action: Alertift.Action, isPreferred: Bool, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, isPreferred: Bool, handler: Handler?) -> Self {
return self.action(action, image: nil, isPreferred: isPreferred, handler: handler)
}

public func action(_ action: Alertift.Action, isPreferred: Bool, handler: ShortHandler? = nil) -> Self {
return self.action(action, image: nil, isPreferred: isPreferred) { _, _, _ in handler?() }
}

/// Add action to Alert
///
/// - Parameters:
Expand All @@ -68,10 +75,14 @@ extension Alertift {
/// - renderMode: Render mode for alert action image. Default is `.automatic`
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: Handler?) -> Self {
return self.action(action, image: image, renderingMode: renderingMode, isPreferred: false, handler: handler)
}

public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, handler: ShortHandler? = nil) -> Self {
return self.action(action, image: image, renderingMode: renderingMode, isPreferred: false) { _, _, _ in handler?() }
}

/// Add action to Alert
///
/// - Parameters:
Expand All @@ -81,7 +92,7 @@ extension Alertift {
/// - isPreferred: If you want to change this action to preferredAction, set true. Default is false.
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: Handler? = nil) -> Self {
public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: Handler?) -> Self {
let alertAction = buildAlertAction(
action,
handler: merge(_alertController.actionWithTextFieldsHandler, handler ?? { (_, _, _)in })
Expand All @@ -95,6 +106,10 @@ extension Alertift {
return self
}

public func action(_ action: Alertift.Action, image: UIImage?, renderingMode: UIImage.RenderingMode = .automatic, isPreferred: Bool, handler: ShortHandler? = nil) -> Self {
return self.action(action, image: image, renderingMode: renderingMode, isPreferred: isPreferred) { _, _, _ in handler?() }
}

/// Add text field to alertController
///
/// - Parameter handler: Define handler if you want to customize UITextField. Default is nil.
Expand Down
11 changes: 10 additions & 1 deletion Sources/AlertType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extension _AlertType where Self: AlertType {
/// AlertType protocol
public protocol AlertType: class {
associatedtype Handler
typealias ShortHandler = () -> Void

/// Add action to Alert
///
Expand All @@ -37,7 +38,15 @@ public protocol AlertType: class {
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
func action(_ action: Alertift.Action, handler: Handler?) -> Self


/// Add action to Alert
///
/// - Parameters:
/// - action: Alert action.
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
func action(_ action: Alertift.Action, handler: ShortHandler?) -> Self

/// UIAlertController
var alertController: UIAlertController { get }
/// default background color of Alert(ActionSheet).
Expand Down

0 comments on commit f9cbb8f

Please sign in to comment.