summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-10-08 14:45:45 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-11-03 13:30:51 +0100
commita9a5da6bc9676e59f7a04466372b359e65de627f (patch)
tree1e93ebcb74e3052b175bb33e8ded05e4dd7b4d14
parent352f38dfe7ac228a95e0194df4b55f1ad4a769dc (diff)
downloadmullvadvpn-a9a5da6bc9676e59f7a04466372b359e65de627f.tar.xz
mullvadvpn-a9a5da6bc9676e59f7a04466372b359e65de627f.zip
SettingsSwitchCell: add setEnabled
-rw-r--r--ios/MullvadVPN/SettingsSwitchCell.swift24
1 files changed, 22 insertions, 2 deletions
diff --git a/ios/MullvadVPN/SettingsSwitchCell.swift b/ios/MullvadVPN/SettingsSwitchCell.swift
index 9911ff5d6a..a504726dff 100644
--- a/ios/MullvadVPN/SettingsSwitchCell.swift
+++ b/ios/MullvadVPN/SettingsSwitchCell.swift
@@ -21,8 +21,6 @@ class SettingsSwitchCell: SettingsCell {
switchContainer.control.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
}
@@ -30,10 +28,20 @@ class SettingsSwitchCell: SettingsCell {
fatalError("init(coder:) has not been implemented")
}
+ func setEnabled(_ isEnabled: Bool) {
+ switchContainer.isEnabled = isEnabled
+ }
+
func setOn(_ isOn: Bool, animated: Bool) {
switchContainer.control.setOn(isOn, animated: animated)
}
+ override func prepareForReuse() {
+ super.prepareForReuse()
+
+ setEnabled(true)
+ }
+
// MARK: - Actions
@objc private func switchValueDidChange() {
@@ -42,6 +50,16 @@ class SettingsSwitchCell: SettingsCell {
// MARK: - Accessibility
+ override var accessibilityTraits: UIAccessibilityTraits {
+ set {
+ super.accessibilityTraits = newValue
+ }
+ get {
+ // Use UISwitch traits to make the entire cell behave as "Switch button"
+ return switchContainer.control.accessibilityTraits
+ }
+ }
+
override var accessibilityLabel: String? {
set {
super.accessibilityLabel = newValue
@@ -79,6 +97,8 @@ class SettingsSwitchCell: SettingsCell {
}
override func accessibilityActivate() -> Bool {
+ guard switchContainer.isEnabled else { return false }
+
let newValue = !self.switchContainer.control.isOn
setOn(newValue, animated: true)