2021-12-06 19:16:03 +03:00
|
|
|
// Copyright © 2021 Tokenary. All rights reserved.
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension UIViewController {
|
|
|
|
|
|
|
|
var inNavigationController: UINavigationController {
|
|
|
|
let navigationController = UINavigationController()
|
|
|
|
navigationController.viewControllers = [self]
|
|
|
|
return navigationController
|
|
|
|
}
|
|
|
|
|
2021-12-07 20:35:14 +03:00
|
|
|
@objc func dismissAnimated() {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
|
2021-12-11 18:31:06 +03:00
|
|
|
func showMessageAlert(text: String, completion: (() -> Void)? = nil) {
|
2021-12-09 15:09:11 +03:00
|
|
|
let alert = UIAlertController(title: text, message: nil, preferredStyle: .alert)
|
2021-12-11 18:31:06 +03:00
|
|
|
let okAction = UIAlertAction(title: Strings.ok, style: .default) { _ in
|
|
|
|
completion?()
|
|
|
|
}
|
2021-12-09 15:09:11 +03:00
|
|
|
alert.addAction(okAction)
|
|
|
|
present(alert, animated: true)
|
|
|
|
}
|
|
|
|
|
2021-12-16 17:03:46 +03:00
|
|
|
func showPasswordAlert(title: String, message: String?, completion: @escaping ((String?) -> Void)) {
|
2021-12-10 19:46:44 +03:00
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
2021-12-10 17:21:31 +03:00
|
|
|
alert.addTextField { textField in
|
|
|
|
textField.isSecureTextEntry = true
|
|
|
|
textField.textContentType = .oneTimeCode
|
|
|
|
}
|
|
|
|
let okAction = UIAlertAction(title: Strings.ok, style: .default) { [weak alert] _ in
|
|
|
|
completion(alert?.textFields?.first?.text ?? "")
|
|
|
|
}
|
2021-12-16 17:03:46 +03:00
|
|
|
let cancelAction = UIAlertAction(title: Strings.cancel, style: .cancel) { _ in
|
|
|
|
completion(nil)
|
|
|
|
}
|
2021-12-10 17:21:31 +03:00
|
|
|
alert.addAction(okAction)
|
|
|
|
alert.addAction(cancelAction)
|
|
|
|
present(alert, animated: true)
|
|
|
|
alert.textFields?.first?.becomeFirstResponder()
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:44:53 +03:00
|
|
|
func endEditingOnTap() -> UITapGestureRecognizer {
|
|
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(endEditing))
|
|
|
|
tapGestureRecognizer.cancelsTouchesInView = false
|
|
|
|
view.addGestureRecognizer(tapGestureRecognizer)
|
|
|
|
return tapGestureRecognizer
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func endEditing() {
|
|
|
|
view.endEditing(true)
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:16:03 +03:00
|
|
|
}
|