Skip to content

Commit

Permalink
Fix the default confirm title.
Browse files Browse the repository at this point in the history
  • Loading branch information
lm2343635 committed Jul 26, 2019
1 parent 4c6ea99 commit 570767a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions RxAlertViewable/Classes/RxAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ extension RxAlert {
return self.init(
title: config.tip,
message: message,
item: UIAlertItem(confirmTitle: config.ok),
category: .single(onConfirm: onConfirm)
)
}
Expand All @@ -114,6 +115,7 @@ extension RxAlert {
return self.init(
title: config.warning,
message: message,
item: UIAlertItem(confirmTitle: config.ok),
category: .single(onConfirm: onConfirm)
)
}
Expand All @@ -122,6 +124,7 @@ extension RxAlert {
return self.init(
title: config.error,
message: message,
item: UIAlertItem(confirmTitle: config.ok),
category: .single(onConfirm: onConfirm)
)
}
Expand Down
15 changes: 12 additions & 3 deletions RxAlertViewable/Classes/RxAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ public protocol RxAlertController: UIViewController {
}

struct UIAlertItem: RxAlertItem {

static let controllerType: RxAlertController.Type = UIAlertController.self

var confirmTitle: String
var denyTitle: String
var denyTitle: String?

init(confirmTitle: String, denyTitle: String? = nil) {
self.confirmTitle = confirmTitle
self.denyTitle = denyTitle
}

}

extension UIAlertController: RxAlertController {
Expand All @@ -55,11 +62,13 @@ extension UIAlertController: RxAlertController {
var denyTitle = RxAlert.config.no
if let alertItem = item as? UIAlertItem {
confirmTitle = alertItem.confirmTitle
denyTitle = alertItem.denyTitle
if let deny = alertItem.denyTitle {
denyTitle = deny
}
}
switch category {
case .single(let onConfirm):
addAction(UIAlertAction(title: title, style: .cancel) { _ in
addAction(UIAlertAction(title: confirmTitle, style: .cancel) { _ in
onConfirm?()
})
case .double(let onConfirm, let onDeny):
Expand Down

0 comments on commit 570767a

Please sign in to comment.