Przeglądaj źródła

Merge pull request #1030 from deltachat/adjust_keyboard_layouts

Adjust keyboard layouts
cyBerta 4 lat temu
rodzic
commit
e4b0d3903c

+ 23 - 13
deltachat-ios/Controller/AccountSetupController.swift

@@ -30,11 +30,13 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
 
     private let tagTextFieldEmail = 100
     private let tagTextFieldPassword = 200
-    private let tagTextFieldImapServer = 300
-    private let tagTextFieldImapLogin = 400
-    private let tagTextFieldSmtpServer = 500
-    private let tagTextFieldSmtpUser = 600
+    private let tagTextFieldImapLogin = 300
+    private let tagTextFieldImapServer = 400
+    private let tagTextFieldImapPort = 500
+    private let tagTextFieldSmtpLogin = 600
     private let tagTextFieldSmtpPassword = 700
+    private let tagTextFieldSmtpServer = 800
+    private let tagTextFieldSmtpPort = 900
 
     // add cells to sections
 
@@ -80,6 +82,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.textField.addTarget(self, action: #selector(emailCellEdited), for: .editingChanged)
         cell.textField.tag = tagTextFieldEmail // will be used to eventually show oAuth-Dialogue when pressing return key
         cell.textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -88,6 +91,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.tag = tagPasswordCell
         cell.textField.tag = tagTextFieldPassword  // will be used to eventually show oAuth-Dialogue when selecting
         cell.textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
+        cell.textField.returnKeyType = advancedSectionShowing ? .next : .default
         return cell
     }()
 
@@ -135,6 +139,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.textField.autocorrectionType = .no
         cell.textField.spellCheckingType = .no
         cell.textField.autocapitalizationType = .none
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -146,6 +151,10 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.setText(text: dcContext.mailUser ?? nil)
         cell.textField.tag = tagTextFieldImapLogin
         cell.tag = tagImapUserCell
+        cell.textField.autocorrectionType = .no
+        cell.textField.spellCheckingType = .no
+        cell.textField.autocapitalizationType = .none
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -167,7 +176,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             delegate: self)
         cell.tag = tagImapPortCell
         cell.setText(text: editablePort(port: dcContext.mailPort))
-        cell.textField.tag = tagImapPortCell
+        cell.textField.tag = tagTextFieldImapPort
         cell.textField.keyboardType = .numberPad
         return cell
     }()
@@ -192,6 +201,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.textField.autocorrectionType = .no
         cell.textField.spellCheckingType = .no
         cell.textField.autocapitalizationType = .none
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -200,9 +210,13 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             descriptionID: "login_smtp_login",
             placeholder: String.localized("automatic"),
             delegate: self)
-        cell.textField.tag = tagTextFieldSmtpUser
+        cell.textField.tag = tagTextFieldSmtpLogin
         cell.setText(text: dcContext.sendUser ?? nil)
         cell.tag = tagSmtpUserCell
+        cell.textField.autocorrectionType = .no
+        cell.textField.spellCheckingType = .no
+        cell.textField.autocapitalizationType = .none
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -213,7 +227,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             delegate: self)
         cell.tag = tagSmtpPortCell
         cell.setText(text: editablePort(port: dcContext.sendPort))
-        cell.textField.tag = tagSmtpPortCell
+        cell.textField.tag = tagTextFieldSmtpPort
         cell.textField.keyboardType = .numberPad
         return cell
     }()
@@ -228,6 +242,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         cell.textField.isSecureTextEntry = true
         cell.textField.tag = tagTextFieldSmtpPassword
         cell.tag = tagSmtpPasswordCell
+        cell.textField.returnKeyType = .next
         return cell
     }()
 
@@ -493,7 +508,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         advancedShowCell.detailTextLabel?.text = willShow ? "\u{2013}" : nil
 
         advancedSectionShowing = willShow // set flag before delete/insert, because cellForRowAt will be triggered and uses this flag
-
+        passwordCell.textField.returnKeyType = willShow ? .next : .default
         if willShow {
             tableView.insertRows(at: advancedIndexPaths, with: .fade)
         } else {
@@ -843,15 +858,10 @@ extension AccountSetupController: UITextFieldDelegate {
     func textFieldShouldReturn(_ textField: UITextField) -> Bool {
         let currentTag = textField.tag
         if let nextField = tableView.viewWithTag(currentTag + 100) as? UITextField {
-            if nextField.tag > tagTextFieldPassword, !advancedSectionShowing {
-                // gets here when trying to activate a collapsed cell
-                return false
-            }
             nextField.becomeFirstResponder()
             return true
         } else {
             textField.resignFirstResponder()
-            emailCell.textField.becomeFirstResponder()
             let indexPath = IndexPath(row: 0, section: 0)
             tableView.scrollToRow(at: indexPath, at: UITableView.ScrollPosition.top, animated: true)
             return true

+ 11 - 0
deltachat-ios/Controller/EditSettingsController.swift

@@ -46,6 +46,8 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     private lazy var nameCell: TextFieldCell = {
         let cell = TextFieldCell(description: String.localized("pref_your_name"), placeholder: String.localized("pref_your_name"))
         cell.setText(text: dcContext.displayname)
+        cell.textFieldDelegate = self
+        cell.textField.returnKeyType = .default
         return cell
     }()
 
@@ -157,3 +159,12 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
     }
 
 }
+
+
+extension EditSettingsController: UITextFieldDelegate {
+
+    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
+        textField.resignFirstResponder()
+        return true
+    }
+}

+ 2 - 0
deltachat-ios/Controller/NewContactController.swift

@@ -118,6 +118,8 @@ extension NewContactController: UITextFieldDelegate {
         } else if textField == nameCell.textField {
             if contactIsValid() {
                 saveContactButtonPressed()
+            } else {
+                emailCell.textField.becomeFirstResponder()
             }
         }
         return true

+ 10 - 0
deltachat-ios/Controller/NewGroupController.swift

@@ -36,6 +36,9 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
         let cell = TextFieldCell(description: String.localized("group_name"), placeholder: String.localized("group_name"))
         cell.onTextFieldChange = self.updateGroupName
         cell.textField.autocorrectionType = UITextAutocorrectionType.no
+        cell.textField.enablesReturnKeyAutomatically = true
+        cell.textField.returnKeyType = .default
+        cell.textFieldDelegate = self
         return cell
     }()
 
@@ -358,3 +361,10 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
         navigationController?.pushViewController(newGroupController, animated: true)
     }
 }
+
+extension NewGroupController: UITextFieldDelegate {
+    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
+        textField.resignFirstResponder()
+        return true
+    }
+}

+ 10 - 1
deltachat-ios/Controller/ProfileInfoViewController.swift

@@ -28,12 +28,13 @@ class ProfileInfoViewController: UITableViewController {
     }()
 
     private lazy var nameCell: TextFieldCell = {
-        let cell =  TextFieldCell.makeNameCell()
+        let cell =  TextFieldCell.makeNameCell(delegate: self)
         cell.placeholder = String.localized("pref_your_name")
         cell.setText(text: dcContext.displayname)
         cell.onTextFieldChange = {[weak self] textField in
             self?.displayName = textField.text
         }
+        cell.textField.returnKeyType = .default
         return cell
     }()
 
@@ -147,3 +148,11 @@ extension ProfileInfoViewController: MediaPickerDelegate {
         updateAvatarCell()
     }
 }
+
+extension ProfileInfoViewController: UITextFieldDelegate {
+
+    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
+        textField.resignFirstResponder()
+        return true
+    }
+}

+ 2 - 1
deltachat-ios/View/TextFieldCell.swift

@@ -173,10 +173,11 @@ class TextFieldCell: UITableViewCell {
         return cell
     }
 
-    static func makePasswordCell(delegate _: UITextFieldDelegate? = nil) -> TextFieldCell {
+    static func makePasswordCell(delegate: UITextFieldDelegate? = nil) -> TextFieldCell {
         let cell = TextFieldCell(description: String.localized("password"), placeholder: String.localized("existing_password"))
         cell.textField.textContentType = UITextContentType.password
         cell.textField.isSecureTextEntry = true
+        cell.textFieldDelegate = delegate
         return cell
     }