Преглед на файлове

add style .safeActionSheet for safer use of UIAlertController on ipad

B. Petersen преди 5 години
родител
ревизия
a2f8741f86

+ 2 - 2
deltachat-ios/Controller/AccountSetupController.swift

@@ -709,7 +709,7 @@ class AccountSetupController: UITableViewController {
 
     private func emptyServer() {
         let alert = UIAlertController(title: String.localized("pref_empty_server_title"),
-            message: String.localized("pref_empty_server_msg"), preferredStyle: .actionSheet)
+            message: String.localized("pref_empty_server_msg"), preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("pref_empty_server_inbox"), style: .destructive, handler: { _ in
             self.emptyServer2ndConfirm(title: String.localized("pref_empty_server_inbox"), flags: Int(DC_EMPTY_INBOX))
         }))
@@ -739,7 +739,7 @@ class AccountSetupController: UITableViewController {
         let dburl = URL(fileURLWithPath: dbfile, isDirectory: false)
         let alert = UIAlertController(title: String.localized("delete_account_ask"),
                                       message: nil,
-                                      preferredStyle: .actionSheet)
+                                      preferredStyle: .safeActionSheet)
 
         alert.addAction(UIAlertAction(title: String.localized("delete_account"), style: .destructive, handler: { _ in
             appDelegate.stop()

+ 2 - 2
deltachat-ios/Controller/ChatListController.swift

@@ -215,7 +215,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
             let dcMsg = DcMsg(id: msgId)
             let dcContact = DcContact(id: dcMsg.fromContactId)
             let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
-            let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
                 let chat = dcMsg.createChat()
                 self.coordinator?.showChat(chatId: chat.id)
@@ -297,7 +297,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
         let alert = UIAlertController(
             title: nil,
             message: String.localized("ask_delete_chat_desktop"),
-            preferredStyle: .actionSheet
+            preferredStyle: .safeActionSheet
         )
         alert.addAction(UIAlertAction(title: String.localized("menu_delete_chat"), style: .destructive, handler: { _ in
             self.dcContext.deleteChat(chatId: chatId)

+ 2 - 2
deltachat-ios/Controller/ChatViewController.swift

@@ -581,7 +581,7 @@ class ChatViewController: MessagesViewController {
     private func confirmationAlert(title: String, actionTitle: String, actionStyle: UIAlertAction.Style = .default, actionHandler: @escaping ((UIAlertAction) -> Void), cancelHandler: ((UIAlertAction) -> Void)? = nil) {
         let alert = UIAlertController(title: title,
                                              message: nil,
-                                             preferredStyle: .actionSheet)
+                                             preferredStyle: .safeActionSheet)
                alert.addAction(UIAlertAction(title: actionTitle, style: actionStyle, handler: actionHandler))
 
                alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: cancelHandler ?? { _ in
@@ -1044,7 +1044,7 @@ extension ChatViewController: MessagesLayoutDelegate {
     }
 
     private func showClipperOptions() {
-        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
+        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .safeActionSheet)
         let galleryAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
         let cameraAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
         let voiceMessageAction = UIAlertAction(title: String.localized("voice_message"), style: .default, handler: voiceMessageButtonPressed(_:))

+ 4 - 4
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -99,7 +99,7 @@ class ContactDetailViewController: UITableViewController {
         let dcContact = DcContact(id: contactId)
         let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
                                       message: nil,
-                                      preferredStyle: .actionSheet)
+                                      preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
             self.dismiss(animated: true, completion: nil)
             let chatId = Int(dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId)))
@@ -136,7 +136,7 @@ class ContactDetailViewController: UITableViewController {
 
     private func toggleBlockContact() {
         if contact.isBlocked {
-            let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: String.localized("ask_unblock_contact"), message: nil, preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
                 self.contact.unblock()
                 self.updateBlockContactCell()
@@ -144,7 +144,7 @@ class ContactDetailViewController: UITableViewController {
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
             present(alert, animated: true, completion: nil)
         } else {
-            let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: String.localized("ask_block_contact"), message: nil, preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("menu_block_contact"), style: .destructive, handler: { _ in
                 self.contact.block()
                 self.updateBlockContactCell()
@@ -162,7 +162,7 @@ class ContactDetailViewController: UITableViewController {
     private func showNotificationSetup() {
         let notificationSetupAlert = UIAlertController(title: "Notifications Setup is not implemented yet",
                                                        message: "But you get an idea where this is going",
-                                                       preferredStyle: .actionSheet)
+                                                       preferredStyle: .safeActionSheet)
         let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil)
         notificationSetupAlert.addAction(cancelAction)
         present(notificationSetupAlert, animated: true, completion: nil)

+ 1 - 1
deltachat-ios/Controller/EditGroupViewController.swift

@@ -91,7 +91,7 @@ class EditGroupViewController: UITableViewController, MediaPickerDelegate {
     }
 
     private func onAvatarTapped() {
-        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
+        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .safeActionSheet)
             let photoAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
             let videoAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
             alert.addAction(photoAction)

+ 1 - 1
deltachat-ios/Controller/EditSettingsController.swift

@@ -154,7 +154,7 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     }
 
     private func onAvatarTapped() {
-        let alert = UIAlertController(title: String.localized("pref_profile_photo"), message: nil, preferredStyle: .actionSheet)
+        let alert = UIAlertController(title: String.localized("pref_profile_photo"), message: nil, preferredStyle: .safeActionSheet)
         let photoAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
         let videoAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
         let deleteAction = UIAlertAction(title: String.localized("delete"), style: .destructive, handler: deleteProfileIconPressed(_:))

+ 2 - 2
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -85,7 +85,7 @@ class GroupChatDetailViewController: UIViewController {
 
     private func leaveGroup() {
         if let userId = currentUser?.id {
-            let alert = UIAlertController(title: String.localized("ask_leave_group"), message: nil, preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: String.localized("ask_leave_group"), message: nil, preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("menu_leave_group"), style: .destructive, handler: { _ in
                 dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(userId))
                 self.editBarButtonItem.isEnabled = false
@@ -248,7 +248,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
 
                 let contact = self.getGroupMember(at: row)
                 let title = String.localizedStringWithFormat(String.localized("ask_remove_members"), contact.nameNAddr)
-                let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
+                let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
                 alert.addAction(UIAlertAction(title: String.localized("remove_desktop"), style: .destructive, handler: { _ in
                     let success = dc_remove_contact_from_chat(mailboxPointer, UInt32(self.chat.id), UInt32(contact.id))
                     if success == 1 {

+ 1 - 1
deltachat-ios/Controller/GroupMembersViewController.swift

@@ -255,7 +255,7 @@ class BlockedContactsViewController: GroupMembersViewController, GroupMemberSele
         if !selected {
             let dcContact = DcContact(id: contactId)
             let title = dcContact.displayName.isEmpty ? dcContact.email : dcContact.displayName
-            let alert = UIAlertController(title: title, message: String.localized("ask_unblock_contact"), preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: title, message: String.localized("ask_unblock_contact"), preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("menu_unblock_contact"), style: .default, handler: { _ in
                 let contact = DcContact(id: contactId)
                 contact.unblock()

+ 1 - 1
deltachat-ios/Controller/MailboxViewController.swift

@@ -45,7 +45,7 @@ class MailboxViewController: ChatViewController {
             let message = messageList[indexPath.section]
             let dcContact = message.fromContact
             let title = String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr)
-            let alert = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
+            let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
             alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
                 let chat = message.createChat()
                 self.coordinator?.showChat(chatId: chat.id)

+ 2 - 2
deltachat-ios/Controller/NewChatViewController.swift

@@ -276,7 +276,7 @@ class NewChatViewController: UITableViewController {
         let contact = DcContact(id: contactId)
         let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_delete_contact"), contact.nameNAddr),
                                       message: nil,
-                                      preferredStyle: .actionSheet)
+                                      preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("delete"), style: .destructive, handler: { _ in
             self.dismiss(animated: true, completion: nil)
             if context.deleteContact(contactId: contactId) {
@@ -294,7 +294,7 @@ class NewChatViewController: UITableViewController {
         let dcContact = DcContact(id: contactId)
         let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
                                       message: nil,
-                                      preferredStyle: .actionSheet)
+                                      preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
             self.dismiss(animated: true, completion: nil)
             self.coordinator?.showNewChat(contactId: contactId)

+ 1 - 1
deltachat-ios/Controller/NewGroupController.swift

@@ -285,7 +285,7 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
     }
 
     private func onAvatarTapped() {
-        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
+        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .safeActionSheet)
             let photoAction = PhotoPickerAlertAction(title: String.localized("gallery"), style: .default, handler: galleryButtonPressed(_:))
             let videoAction = PhotoPickerAlertAction(title: String.localized("camera"), style: .default, handler: cameraButtonPressed(_:))
             alert.addAction(photoAction)

+ 2 - 2
deltachat-ios/Controller/SettingsController.swift

@@ -240,7 +240,7 @@ internal final class SettingsViewController: QuickTableViewController {
     }
 
     private func createBackup(_: Row) {
-        let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .actionSheet)
+        let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
             self.dismiss(animated: true, completion: nil)
             let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
@@ -277,7 +277,7 @@ internal final class SettingsViewController: QuickTableViewController {
     }
 
     private func sendAsm(_: Row) {
-        let askAlert = UIAlertController(title: String.localized("autocrypt_send_asm_explain_before"), message: nil, preferredStyle: .actionSheet)
+        let askAlert = UIAlertController(title: String.localized("autocrypt_send_asm_explain_before"), message: nil, preferredStyle: .safeActionSheet)
         askAlert.addAction(UIAlertAction(title: String.localized("autocrypt_send_asm_title"), style: .default, handler: { _ in
             let waitAlert = UIAlertController(title: String.localized("one_moment"), message: nil, preferredStyle: .alert)
             waitAlert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: { _ in self.dcContext.stopOngoingProcess() }))

+ 14 - 0
deltachat-ios/Extensions/Extensions.swift

@@ -57,3 +57,17 @@ extension UIViewController {
         view.endEditing(true)
     }
 }
+
+extension UIAlertController.Style {
+    // ipad allow .actionSheet only presented for some concrete controls (and cashes otherwise!)
+    // whereas iphone can present .actionSheet unconditionally.
+    // .safeActionSheet returns .alert for systems that do not support .actionSheet unconditionally.
+    // if in doubt, always prefer .safeActionSheet over .actionSheet
+    static var safeActionSheet: UIAlertController.Style {
+        if UIDevice.current.userInterfaceIdiom == .pad {
+            return .alert
+        } else {
+            return .actionSheet
+        }
+    }
+}