Просмотр исходного кода

add 'Done' button, tweak layout

- the 'Done' button is needed as otherwise
  it is hard to close the selector in landscape mode

- in general, it seems better for consistency
  to always have a 'Done'/'Cancel' or sth. like that

- 'Cancel' moves to the right of the only button
  to be consistent with os
  (i aim to write some more words to that in a file,
  this is also wrong at some other places)

- adapting the title when things are about deletion and not switching
B. Petersen 2 лет назад
Родитель
Сommit
b0a864d1ad
1 измененных файлов с 21 добавлено и 4 удалено
  1. 21 4
      deltachat-ios/Controller/AccountSwitchViewController.swift

+ 21 - 4
deltachat-ios/Controller/AccountSwitchViewController.swift

@@ -20,10 +20,17 @@ class AccountSwitchViewController: UITableViewController {
         return btn
     }()
 
-    private lazy var cancelButton: UIBarButtonItem = {
+    private lazy var cancelEditButton: UIBarButtonItem = {
         let btn = UIBarButtonItem(barButtonSystemItem: .cancel,
                                   target: self,
-                                  action: #selector(cancelAction))
+                                  action: #selector(cancelEditAction))
+        return btn
+    }()
+
+    private lazy var doneButton: UIBarButtonItem = {
+        let btn = UIBarButtonItem(barButtonSystemItem: .done,
+                                  target: self,
+                                  action: #selector(doneAction))
         return btn
     }()
 
@@ -52,6 +59,7 @@ class AccountSwitchViewController: UITableViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         navigationItem.setLeftBarButton(editButton, animated: false)
+        navigationItem.setRightBarButton(doneButton, animated: false)
     }
 
     private func setupSubviews() {
@@ -201,17 +209,26 @@ class AccountSwitchViewController: UITableViewController {
 
     @objc private func editAction() {
         logger.debug("edit Action")
-        navigationItem.setLeftBarButton(cancelButton, animated: false)
+        title = String.localized("delete_account")
+        navigationItem.setLeftBarButton(nil, animated: true)
+        navigationItem.setRightBarButton(cancelEditButton, animated: true)
         showAccountDeletion = true
         tableView.reloadData()
     }
 
-    @objc private func cancelAction() {
+    @objc private func cancelEditAction() {
         logger.debug("cancel Action")
+        title = String.localized("switch_account")
         navigationItem.setLeftBarButton(editButton, animated: false)
+        navigationItem.setRightBarButton(doneButton, animated: false)
         showAccountDeletion = false
         tableView.reloadData()
     }
+
+    @objc private func doneAction() {
+        logger.debug("done Action")
+        dismiss(animated: true)
+    }
 }
 
 class AccountCell: UITableViewCell {