diff options
| author | Andrew Bulhak <andrew.bulhak@mullvad.net> | 2025-02-06 14:57:12 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-02-07 09:52:10 +0100 |
| commit | 2d898e7a5a44f0d5f7e6ba06f19342447e980b7b (patch) | |
| tree | dc3d5934497da04992758cb376cb12a9e9231118 | |
| parent | f278ba37d6aa88b0eaec80f1785938fb885c9eb6 (diff) | |
| download | mullvadvpn-2d898e7a5a44f0d5f7e6ba06f19342447e980b7b.tar.xz mullvadvpn-2d898e7a5a44f0d5f7e6ba06f19342447e980b7b.zip | |
Modify custom-value-selection logic to not rely on input focus
| -rw-r--r-- | ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift b/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift index 3560a870d6..16377f807a 100644 --- a/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift +++ b/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift @@ -59,6 +59,8 @@ struct SingleChoiceList<Value>: View where Value: Equatable { let tableAccessibilityIdentifier: String let itemDescription: (Value) -> String let customFieldMode: CustomFieldMode + // a latch to keep the custom field selected through changes of focus until the user taps elsewhere + @State var customFieldSelected = false /// The configuration for the field for a custom value row enum CustomFieldMode { @@ -206,7 +208,7 @@ struct SingleChoiceList<Value>: View where Value: Equatable { // Construct a literal row for a specific literal value private func literalRow(_ item: Value) -> some View { row( - isSelected: value.wrappedValue == item && !customValueIsFocused + isSelected: value.wrappedValue == item && !customFieldSelected ) { Text(verbatim: itemDescription(item)) Spacer() @@ -215,6 +217,7 @@ struct SingleChoiceList<Value>: View where Value: Equatable { value.wrappedValue = item customValueIsFocused = false customValueInput = "" + customFieldSelected = false } } @@ -229,7 +232,7 @@ struct SingleChoiceList<Value>: View where Value: Equatable { fromValue: @escaping (Value) -> String? ) -> some View { row( - isSelected: value.wrappedValue == toValue(customValueInput) || customValueIsFocused + isSelected: value.wrappedValue == toValue(customValueInput) || customFieldSelected ) { Text(label) Spacer() @@ -304,6 +307,7 @@ struct SingleChoiceList<Value>: View where Value: Equatable { } } .onTapGesture { + customFieldSelected = true if let v = toValue(customValueInput) { value.wrappedValue = v } else { |
