aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift')
-rw-r--r--WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift25
1 files changed, 25 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift b/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift
new file mode 100644
index 0000000..8064fff
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import UIKit
+
+class ConfirmationAlertPresenter {
+ static func showConfirmationAlert(message: String, buttonTitle: String, from sourceObject: AnyObject, presentingVC: UIViewController, onConfirmed: @escaping (() -> Void)) {
+ let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
+ onConfirmed()
+ }
+ let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
+ let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
+ alert.addAction(destroyAction)
+ alert.addAction(cancelAction)
+
+ if let sourceView = sourceObject as? UIView {
+ alert.popoverPresentationController?.sourceView = sourceView
+ alert.popoverPresentationController?.sourceRect = sourceView.bounds
+ } else if let sourceBarButtonItem = sourceObject as? UIBarButtonItem {
+ alert.popoverPresentationController?.barButtonItem = sourceBarButtonItem
+ }
+
+ presentingVC.present(alert, animated: true, completion: nil)
+ }
+}