fix alert vc for iPad

This commit is contained in:
Ryan Zhao 2022-02-24 16:02:24 +11:00
parent a8c7f517eb
commit b32a8cbab2
7 changed files with 23 additions and 13 deletions

View File

@ -157,7 +157,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
} catch {
let alert = UIAlertController(title: "Session", message: "An error occurred.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
return present(alert, animated: true, completion: nil)
return presentAlert(alert)
}
let type = urlResourceValues.typeIdentifier ?? (kUTTypeData as String)
guard urlResourceValues.isDirectory != true else {
@ -556,7 +556,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
}))
}
}
present(sheet, animated: true, completion: nil)
presentAlert(sheet)
}
func handleViewItemDoubleTapped(_ viewItem: ConversationViewItem) {
@ -691,7 +691,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
OpenGroupAPIV2.ban(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
presentAlert(alert)
}
func banAndDeleteAllMessages(_ viewItem: ConversationViewItem) {
@ -705,7 +705,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
OpenGroupAPIV2.banAndDeleteAllMessages(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
presentAlert(alert)
}
func handleQuoteViewCancelButtonTapped() {

View File

@ -66,7 +66,7 @@ final class JoinOpenGroupModal : Modal {
guard let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: url) else {
let alert = UIAlertController(title: "Couldn't Join", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil))
return presentingViewController!.present(alert, animated: true, completion: nil)
return presentingViewController!.presentAlert(alert)
}
presentingViewController!.dismiss(animated: true, completion: nil)
Storage.shared.write { [presentingViewController = self.presentingViewController!] transaction in
@ -78,7 +78,7 @@ final class JoinOpenGroupModal : Modal {
.catch(on: DispatchQueue.main) { error in
let alert = UIAlertController(title: "Couldn't Join", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil))
presentingViewController.present(alert, animated: true, completion: nil)
presentingViewController.presentAlert(alert)
}
}
}

View File

@ -348,7 +348,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
})
alert.addAction(UIAlertAction(title: NSLocalizedString("TXT_CANCEL_TITLE", comment: ""), style: .default) { _ in })
guard let self = self else { return }
self.present(alert, animated: true, completion: nil)
self.presentAlert(alert)
}
delete.backgroundColor = Colors.destructive

View File

@ -91,7 +91,7 @@ final class PNModeVC : BaseVC, OptionViewDelegate {
let title = NSLocalizedString("vc_pn_mode_no_option_picked_modal_title", comment: "")
let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil))
return present(alert, animated: true, completion: nil)
return presentAlert(alert)
}
UserDefaults.standard[.isUsingFullAPNs] = (selectedOptionView == apnsOptionView)
TSAccountManager.sharedInstance().didRegister()

View File

@ -392,7 +392,7 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
let message = isMaxFileSizeExceeded ? "Please select a smaller photo and try again" : "Please check your internet connection and try again"
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil))
self?.present(alert, animated: true, completion: nil)
self?.presentAlert(alert)
}
}
}, requiresSync: true)

View File

@ -225,7 +225,7 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
alert.addAction(UIAlertAction(title: "BUTTON_OK".localized(), style: .default, handler: { _ in
self.extensionContext!.cancelRequest(withError: error)
}))
present(alert, animated: true, completion: nil)
presentAlert(alert)
}
// MARK: Attachment Prep

View File

@ -132,11 +132,12 @@ public extension UIView {
@objc
public extension UIViewController {
public func presentAlert(_ alert: UIAlertController) {
func presentAlert(_ alert: UIAlertController) {
self.presentAlert(alert, animated: true)
}
public func presentAlert(_ alert: UIAlertController, animated: Bool) {
func presentAlert(_ alert: UIAlertController, animated: Bool) {
setupForIPadIfNeeded(alert: alert)
self.present(alert,
animated: animated,
completion: {
@ -144,7 +145,8 @@ public extension UIViewController {
})
}
public func presentAlert(_ alert: UIAlertController, completion: @escaping (() -> Void)) {
func presentAlert(_ alert: UIAlertController, completion: @escaping (() -> Void)) {
setupForIPadIfNeeded(alert: alert)
self.present(alert,
animated: true,
completion: {
@ -153,6 +155,14 @@ public extension UIViewController {
completion()
})
}
private func setupForIPadIfNeeded(alert: UIAlertController) {
if UIDevice.current.isIPad {
alert.popoverPresentationController?.permittedArrowDirections = []
alert.popoverPresentationController?.sourceView = self.view
alert.popoverPresentationController?.sourceRect = self.view.bounds
}
}
}
// MARK: -