Skip to content

Commit aef402e

Browse files
Shivam BhallaShivam Bhalla
authored andcommitted
Notify on background tap
1 parent 0170228 commit aef402e

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

CFAlertViewController/CFAlertViewController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import UIKit
1313
class CFAlertViewController: UIViewController {
1414

1515
// MARK: - Declarations
16-
public typealias CFAlertViewControllerDismissBlock = () -> ()
16+
public typealias CFAlertViewControllerDismissBlock = (_ isBackgroundTapped: Bool) -> ()
1717

1818
@objc public enum CFAlertControllerStyle : Int {
1919
case alert = 0
@@ -213,6 +213,10 @@ class CFAlertViewController: UIViewController {
213213
}
214214

215215
public func dismissAlert(withAnimation animate: Bool, completion: ((_: Void) -> Void)?) {
216+
dismissAlert(withAnimation: animate, isBackgroundTapped: false, completion: completion)
217+
}
218+
219+
private func dismissAlert(withAnimation animate: Bool, isBackgroundTapped: Bool, completion: ((_: Void) -> Void)?) {
216220

217221
// Dismiss Self
218222
self.dismiss(animated: animate, completion: {() -> Void in
@@ -222,7 +226,7 @@ class CFAlertViewController: UIViewController {
222226
}
223227
// Call Dismiss Block
224228
if let dismissHandler = self.dismissHandler {
225-
dismissHandler()
229+
dismissHandler(isBackgroundTapped)
226230
}
227231
})
228232
}
@@ -310,9 +314,9 @@ class CFAlertViewController: UIViewController {
310314
// Close Keyboard
311315
self.view.endEditing(true)
312316
}
313-
else if self.shouldDismissOnBackgroundTap {
317+
else if shouldDismissOnBackgroundTap {
314318
// Dismiss Alert
315-
self.dismissAlert(withAnimation: true, completion: {() -> Void in
319+
dismissAlert(withAnimation: true, isBackgroundTapped: true, completion: {() -> Void in
316320
// Simulate Cancel Button
317321
for existingAction: CFAlertAction in self.actionList {
318322
if existingAction.style == .Cancel {

Demo/CFAlertViewControllerDemo/View Controller/HomeTableViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ - (void) showEmptyFieldsAlert {
238238
message:@"Please set some properties of Alert view"
239239
textAlignment:NSTextAlignmentCenter
240240
preferredStyle:CFAlertControllerStyleAlert
241-
didDismissAlertHandler:^{
241+
didDismissAlertHandler:^(BOOL isBackgroundTapped) {
242242
NSLog(@"Alert Dismissed");
243243
}];
244244

0 commit comments

Comments
 (0)