diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-07-16 14:16:57 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-07-16 14:16:57 +0200 |
| commit | f1b9160bb180191e128c07c74e5be352838ddf44 (patch) | |
| tree | 40dc4296104b7f267c7564be9b91078282f1d17b | |
| parent | 061c1bcee614716d6805d9bd2820ba1a788a27a9 (diff) | |
| parent | 5f485135b75aa34ab327a66d99bdb22231d85768 (diff) | |
| download | mullvadvpn-f1b9160bb180191e128c07c74e5be352838ddf44.tar.xz mullvadvpn-f1b9160bb180191e128c07c74e5be352838ddf44.zip | |
Merge branch 'preferences-ax'
| -rw-r--r-- | ios/MullvadVPN/AppButton.swift | 2 | ||||
| -rw-r--r-- | ios/MullvadVPN/PreferencesViewController.swift | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/SettingsSwitchCell.swift | 67 |
3 files changed, 64 insertions, 9 deletions
diff --git a/ios/MullvadVPN/AppButton.swift b/ios/MullvadVPN/AppButton.swift index 799c4b933f..a22bf818b1 100644 --- a/ios/MullvadVPN/AppButton.swift +++ b/ios/MullvadVPN/AppButton.swift @@ -71,6 +71,8 @@ private extension UIControl.State { private func commonInit() { imageAlignment = .trailing contentHorizontalAlignment = .leading + + accessibilityTraits.insert(.link) } private func updateAttributedTitle(string: String?) { diff --git a/ios/MullvadVPN/PreferencesViewController.swift b/ios/MullvadVPN/PreferencesViewController.swift index 726bba49d3..f895923bb3 100644 --- a/ios/MullvadVPN/PreferencesViewController.swift +++ b/ios/MullvadVPN/PreferencesViewController.swift @@ -75,7 +75,7 @@ class PreferencesViewController: UITableViewController, TunnelObserver { let cell = cell as! SettingsSwitchCell cell.titleLabel.text = NSLocalizedString("Block ads", comment: "") - cell.switchControl.setOn(self.dnsSettings?.blockAdvertising ?? false, animated: false) + cell.setOn(self.dnsSettings?.blockAdvertising ?? false, animated: false) cell.action = { [weak self] (isOn) in self?.dnsSettings?.blockAdvertising = isOn self?.saveDNSSettings() @@ -87,7 +87,7 @@ class PreferencesViewController: UITableViewController, TunnelObserver { let cell = cell as! SettingsSwitchCell cell.titleLabel.text = NSLocalizedString("Block trackers", comment: "") - cell.switchControl.setOn(self.dnsSettings?.blockTracking ?? false, animated: false) + cell.setOn(self.dnsSettings?.blockTracking ?? false, animated: false) cell.action = { [weak self] (isOn) in self?.dnsSettings?.blockTracking = isOn self?.saveDNSSettings() diff --git a/ios/MullvadVPN/SettingsSwitchCell.swift b/ios/MullvadVPN/SettingsSwitchCell.swift index d644c5cf77..9911ff5d6a 100644 --- a/ios/MullvadVPN/SettingsSwitchCell.swift +++ b/ios/MullvadVPN/SettingsSwitchCell.swift @@ -10,27 +10,80 @@ import UIKit class SettingsSwitchCell: SettingsCell { - let switchContainer = CustomSwitchContainer() - var switchControl: CustomSwitch { - return switchContainer.control - } + private let switchContainer = CustomSwitchContainer() var action: ((Bool) -> Void)? override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - self.accessoryView = switchContainer + accessoryView = switchContainer + + switchContainer.control.addTarget(self, action: #selector(switchValueDidChange), for: .valueChanged) - switchControl.addTarget(self, action: #selector(switchValueDidChange), for: .valueChanged) + // Use UISwitch traits to make the entire cell behave as "Switch button" + accessibilityTraits = switchContainer.control.accessibilityTraits + isAccessibilityElement = true } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + func setOn(_ isOn: Bool, animated: Bool) { + switchContainer.control.setOn(isOn, animated: animated) + } + + // MARK: - Actions + @objc private func switchValueDidChange() { - self.action?(self.switchControl.isOn) + action?(self.switchContainer.control.isOn) } + // MARK: - Accessibility + + override var accessibilityLabel: String? { + set { + super.accessibilityLabel = newValue + } + get { + return titleLabel.text + } + } + + override var accessibilityValue: String? { + set { + super.accessibilityValue = newValue + } + get { + return self.switchContainer.control.accessibilityValue + } + } + + override var accessibilityFrame: CGRect { + set { + super.accessibilityFrame = newValue + } + get { + return UIAccessibility.convertToScreenCoordinates(self.bounds, in: self) + } + } + + override var accessibilityPath: UIBezierPath? { + set { + super.accessibilityPath = newValue + } + get { + return UIBezierPath(roundedRect: accessibilityFrame, cornerRadius: 4) + } + } + + override func accessibilityActivate() -> Bool { + let newValue = !self.switchContainer.control.isOn + + setOn(newValue, animated: true) + action?(newValue) + + return true + } } |
