diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-03-22 15:10:03 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-03-24 14:02:45 +0100 |
| commit | a163276cdb1763e14b6a2e0838d4d74d66fc62e8 (patch) | |
| tree | bcbca4fde8f0f4dcf5a3263b54030efe622358e3 | |
| parent | 826a553a3aec167835aed2b3ac450f966c797766 (diff) | |
| download | mullvadvpn-a163276cdb1763e14b6a2e0838d4d74d66fc62e8.tar.xz mullvadvpn-a163276cdb1763e14b6a2e0838d4d74d66fc62e8.zip | |
Login: disable "create account" button on iPad once user starts typing in the account token
| -rw-r--r-- | ios/MullvadVPN/LoginViewController.swift | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/ios/MullvadVPN/LoginViewController.swift b/ios/MullvadVPN/LoginViewController.swift index 53d13d3f8d..fa63d40ed7 100644 --- a/ios/MullvadVPN/LoginViewController.swift +++ b/ios/MullvadVPN/LoginViewController.swift @@ -144,11 +144,17 @@ class LoginViewController: UIViewController, RootContainment { return false } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + if traitCollection.userInterfaceIdiom != previousTraitCollection?.userInterfaceIdiom { + updateCreateButtonEnabled() + } + } + // MARK: - Public func reset() { - loginState = .default contentView.accountInputGroup.clearToken() + loginState = .default updateKeyboardToolbar() } @@ -160,8 +166,11 @@ class LoginViewController: UIViewController, RootContainment { loginState = .default } - // Enable the log in button in the keyboard toolbar + // Enable the log in button in the keyboard toolbar. updateKeyboardToolbar() + + // Update "create account" button state. + updateCreateButtonEnabled() } // MARK: - Actions @@ -206,24 +215,17 @@ class LoginViewController: UIViewController, RootContainment { private func loginStateDidChange() { contentView.accountInputGroup.setLoginState(loginState, animated: true) - // Keep the settings button disabled to prevent user from going to settings while - // authentication or during the delay after the successful login and transition to the main - // controller. switch loginState { case .authenticating: contentView.activityIndicator.startAnimating() - contentView.createAccountButton.isEnabled = false - - case .success: - contentView.activityIndicator.stopAnimating() - case .default, .failure: - contentView.createAccountButton.isEnabled = true + case .success, .default, .failure: contentView.activityIndicator.stopAnimating() } updateDisplayedMessage() updateStatusIcon() + updateCreateButtonEnabled() } private func updateStatusIcon() { @@ -269,6 +271,27 @@ class LoginViewController: UIViewController, RootContainment { accountInputAccessoryLoginButton.isEnabled = canBeginLogin() } + private func updateCreateButtonEnabled() { + let isEnabled: Bool + + switch loginState { + case .failure, .default: + // Disable "Create account" button on iPad as user types in the account token, + // however leave it enabled on iPhone to avoid confusion to why it's being disabled + // since it's likely overlayed by keyboard. + if case .pad = self.traitCollection.userInterfaceIdiom { + isEnabled = contentView.accountInputGroup.textField.text?.isEmpty ?? true + } else { + isEnabled = true + } + + case .success, .authenticating: + isEnabled = false + } + + contentView.createAccountButton.isEnabled = isEnabled + } + private func canBeginLogin() -> Bool { return contentView.accountInputGroup.satisfiesMinimumTokenLengthRequirement } |
