diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-07-19 10:47:53 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-07-19 10:47:53 +0200 |
| commit | f3c78fd89f520178b7f21eff320e5e18d32b9ec7 (patch) | |
| tree | 14aa78570cdcb7753a243348545d35bde2c7a9a4 | |
| parent | f1b9160bb180191e128c07c74e5be352838ddf44 (diff) | |
| parent | e35cbc97f3e315f764b3f15369db16efb6510c0f (diff) | |
| download | mullvadvpn-f3c78fd89f520178b7f21eff320e5e18d32b9ec7.tar.xz mullvadvpn-f3c78fd89f520178b7f21eff320e5e18d32b9ec7.zip | |
Merge branch 'login-ax'
| -rw-r--r-- | ios/MullvadVPN/AccountInputGroupView.swift | 47 | ||||
| -rw-r--r-- | ios/MullvadVPN/AccountTextField.swift | 31 | ||||
| -rw-r--r-- | ios/MullvadVPN/en.lproj/Localizable.strings | 2 |
3 files changed, 59 insertions, 21 deletions
diff --git a/ios/MullvadVPN/AccountInputGroupView.swift b/ios/MullvadVPN/AccountInputGroupView.swift index a5b5d17277..b67a752407 100644 --- a/ios/MullvadVPN/AccountInputGroupView.swift +++ b/ios/MullvadVPN/AccountInputGroupView.swift @@ -18,9 +18,9 @@ class AccountInputGroupView: UIView { let sendButton: UIButton = { let button = UIButton(type: .custom) - button.setImage(UIImage(named: "IconArrow"), for: .normal) button.translatesAutoresizingMaskIntoConstraints = false - button.backgroundColor = .successColor + button.setImage(UIImage(named: "IconArrow"), for: .normal) + button.accessibilityLabel = NSLocalizedString("ACCOUNT_INPUT_LOGIN_BUTTON_ACCESSIBILITY_LABEL", comment: "") return button }() @@ -150,10 +150,11 @@ class AccountInputGroupView: UIView { updateAppearance() updateTextFieldEnabled() - updateSendButtonVisible(animated: false) + updateSendButtonAppearance(animated: false) updateKeyboardReturnKeyEnabled() addTextFieldNotificationObservers() + addAccessibilityNotificationObservers() sendButton.addTarget(self, action: #selector(handleSendButton(_:)), for: .touchUpInside) } @@ -166,7 +167,7 @@ class AccountInputGroupView: UIView { updateAppearance() updateTextFieldEnabled() - updateSendButtonVisible(animated: animated) + updateSendButtonAppearance(animated: animated) } func setOnReturnKey(_ onReturnKey: ((AccountInputGroupView) -> Bool)?) { @@ -183,12 +184,12 @@ class AccountInputGroupView: UIView { func setToken(_ token: String) { privateTextField.autoformattingText = token - updateSendButtonVisible(animated: false) + updateSendButtonAppearance(animated: false) } func clearToken() { privateTextField.autoformattingText = "" - updateSendButtonVisible(animated: false) + updateSendButtonAppearance(animated: false) } // MARK: - CALayerDelegate @@ -219,7 +220,7 @@ class AccountInputGroupView: UIView { } @objc private func textDidChange() { - updateSendButtonVisible(animated: true) + updateSendButtonAppearance(animated: true) updateKeyboardReturnKeyEnabled() } @@ -266,17 +267,28 @@ class AccountInputGroupView: UIView { } } - private func updateSendButtonVisible(animated: Bool) { + private func updateSendButtonAppearance(animated: Bool) { let actions = { switch self.loginState { case .authenticating, .success: - self.sendButton.alpha = 0 + // Always show the send button when voice over is running to make it discoverable + self.sendButton.alpha = UIAccessibility.isVoiceOverRunning ? 1 : 0 + + self.sendButton.isEnabled = false + self.sendButton.backgroundColor = .lightGray case .default, .failure: let isEnabled = self.satisfiesMinimumTokenLengthRequirement - self.sendButton.alpha = isEnabled ? 1 : 0 - self.sendButton.isUserInteractionEnabled = isEnabled + // Always show the send button when voice over is running to make it discoverable + if UIAccessibility.isVoiceOverRunning { + self.sendButton.alpha = 1 + } else { + self.sendButton.alpha = isEnabled ? 1 : 0 + } + + self.sendButton.isEnabled = isEnabled + self.sendButton.backgroundColor = isEnabled ? .successColor : .lightGray } } @@ -288,7 +300,7 @@ class AccountInputGroupView: UIView { actions() } } - + private func updateKeyboardReturnKeyEnabled() { privateTextField.enableReturnKey = satisfiesMinimumTokenLengthRequirement } @@ -309,4 +321,15 @@ class AccountInputGroupView: UIView { borderPath.stroke(with: .clear, alpha: 0) } } + + // MARK: - Accessibility + + private func addAccessibilityNotificationObservers() { + NotificationCenter.default.addObserver(self, selector: #selector(voiceOverStatusDidChange(_:)), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) + } + + @objc private func voiceOverStatusDidChange(_ notification: Notification) { + updateSendButtonAppearance(animated: true) + } + } diff --git a/ios/MullvadVPN/AccountTextField.swift b/ios/MullvadVPN/AccountTextField.swift index a7ddbb7a84..7a1d00dc5d 100644 --- a/ios/MullvadVPN/AccountTextField.swift +++ b/ios/MullvadVPN/AccountTextField.swift @@ -16,15 +16,7 @@ class AccountTextField: UITextField, UITextFieldDelegate { override init(frame: CGRect) { super.init(frame: frame) - setup() - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - setup() - } - private func setup() { backgroundColor = UIColor.clear delegate = self @@ -38,6 +30,10 @@ class AccountTextField: UITextField, UITextFieldDelegate { ) } + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + var autoformattingText: String { set { input.replace(with: newValue) @@ -76,7 +72,7 @@ class AccountTextField: UITextField, UITextFieldDelegate { return onReturnKey?(self) ?? true } - // MARK: - Keyboard notifications + // MARK: - Notifications @objc private func keyboardWillShow(_ notification: Notification) { if self.isFirstResponder { @@ -84,6 +80,8 @@ class AccountTextField: UITextField, UITextFieldDelegate { } } + // MARK: - Keyboard + private func updateKeyboardReturnKey() { setEnableKeyboardReturnKey(enableReturnKey) } @@ -95,4 +93,19 @@ class AccountTextField: UITextField, UITextFieldDelegate { } } + // MARK: - Accessibility + + override var accessibilityValue: String? { + set { + super.accessibilityValue = newValue + } + get { + if self.text?.isEmpty ?? true { + return "" + } else { + return super.accessibilityValue + } + } + } + } diff --git a/ios/MullvadVPN/en.lproj/Localizable.strings b/ios/MullvadVPN/en.lproj/Localizable.strings index 0e83a02148..45681aea70 100644 --- a/ios/MullvadVPN/en.lproj/Localizable.strings +++ b/ios/MullvadVPN/en.lproj/Localizable.strings @@ -16,3 +16,5 @@ "ACCOUNT_EXPIRY_SYSTEM_NOTIFICATION_BODY" = "Account credit expires in 3 days. Buy more credit."; "ACCOUNT_EXPIRY_INAPP_NOTIFICATION_TITLE" = "ACCOUNT CREDIT EXPIRES SOON"; "ACCOUNT_EXPIRY_INAPP_NOTIFICATION_BODY" = "%@ left. Buy more credit."; + +"ACCOUNT_INPUT_LOGIN_BUTTON_ACCESSIBILITY_LABEL" = "Log in"; |
