diff options
author | Roopesh Chander <roop@roopc.net> | 2019-03-19 01:24:06 +0530 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-18 14:54:05 -0600 |
commit | fc163fc9ff8e6408cfe262d758c402aada920cc1 (patch) | |
tree | 237a5a93e9966919b2a8adc8fe2590f0f0ba0791 /WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift | |
parent | iOS: Tunnels list: Ability to remove multiple tunnels at a time (diff) | |
download | wireguard-apple-fc163fc9ff8e6408cfe262d758c402aada920cc1.tar.xz wireguard-apple-fc163fc9ff8e6408cfe262d758c402aada920cc1.zip |
iOS: Consolidate all showConfirmationAlert()s into one place
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/ConfirmationAlertPresenter.swift | 25 |
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) + } +} |