Skip to content

Commit

Permalink
adding onDismiss action
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormesquita committed Mar 25, 2019
1 parent a502da9 commit 267116c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Example/Malert.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.demo.Malert;
PRODUCT_BUNDLE_IDENTIFIER = com.mesquita.malert;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
Expand All @@ -769,7 +769,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.demo.Malert;
PRODUCT_BUNDLE_IDENTIFIER = com.mesquita.malert;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
Expand Down
4 changes: 4 additions & 0 deletions Example/Malert/listExamples/ListExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ extension ListExamplesViewController {
alert.cornerRadius = 0
alert.buttonsBottomMargin = 16
alert.buttonsSideMargin = 16

alert.onDismissMalert {
print("dismissed")
}

let action = MalertAction(title: "THAT'S IT")
action.tintColor = .white
Expand Down
2 changes: 1 addition & 1 deletion Malert.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Pod::Spec.new do |s|
s.name = 'Malert'
s.version = '3.1.3'
s.version = '3.1.4'
s.summary = 'A simple, easy and very customizable alert'
s.description = <<-DESC
Malert came to facilitate make custom alert views, introducing as `UIAlertController`.
Expand Down
8 changes: 2 additions & 6 deletions Malert/Classes/Malert/Malert+Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ extension Malert {

let isPointInMalertView = malertView.frame.contains(point)
if !isPointInMalertView {
dismiss(animated: true) {
print("dismissed")
}
dismiss(animated: true, completion: self.completionBlock)
}
} else {
self.view.endEditing(true)
Expand All @@ -29,9 +27,7 @@ extension Malert: MalertActionCallbackProtocol {

func didTapOnAction() {
if dismissOnActionTapped {
dismiss(animated: true) {
print("dismissed")
}
dismiss(animated: true, completion: self.completionBlock)
}
}
}
10 changes: 9 additions & 1 deletion Malert/Classes/Malert/Malert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Malert: BaseMalertViewController {

let tapToDismiss: Bool
let dismissOnActionTapped: Bool
var completionBlock: (() -> Void)?

lazy var visibleView: UIView = {
let visibleView = UIView()
Expand Down Expand Up @@ -84,7 +85,9 @@ public class Malert: BaseMalertViewController {
}

deinit {
#if DEBUG
print("dealloc ---> Malert")
#endif
}
}

Expand Down Expand Up @@ -158,7 +161,7 @@ extension Malert {
get { return malertView.buttonsSideMargin }
set { malertView.buttonsSideMargin = newValue }
}

public var buttonsBottomMargin: CGFloat {
get { return malertView.buttonsBottomMargin }
set { malertView.buttonsBottomMargin = newValue }
Expand All @@ -174,7 +177,12 @@ extension Malert {
set { malertView.buttonsFont = newValue }
}

/* Actions */
public func addAction(_ malertButton: MalertAction) {
malertView.addButton(malertButton, actionCallback: self)
}

public func onDismissMalert(_ block: @escaping (() -> Void)) {
self.completionBlock = block
}
}

0 comments on commit 267116c

Please sign in to comment.