diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2024-11-28 13:38:14 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-11-28 13:38:14 +0100 |
| commit | aac6336902708e2176eda2366658fd30f80095ce (patch) | |
| tree | e7c386d557ddddb174db14b8814550c285886a1a | |
| parent | 30733c7950213767ccb0f2e3caacb153b3cb9777 (diff) | |
| parent | aa1b5a11dda98dd5b44ffed3faa5b11f6053efb8 (diff) | |
| download | mullvadvpn-aac6336902708e2176eda2366658fd30f80095ce.tar.xz mullvadvpn-aac6336902708e2176eda2366658fd30f80095ce.zip | |
Merge branch 'IOS-953-shadowsocks-port-selector-bug'
| -rw-r--r-- | ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift b/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift index 182e2c9885..0b48846d86 100644 --- a/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift +++ b/ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift @@ -272,7 +272,12 @@ struct SingleChoiceList<Value>: View where Value: Equatable { // this is not a valid value, so we fall back to the // initial value, showing the invalid-value state if // the field is not empty - if let initialValue { + // As `customValueIsFocused` takes a while to propagate, we + // only reset the field to the initial value if it was previously + // a custom value. Otherwise, blanking this field when the user + // has selected another field will cause the user's choice to be + // overridden. + if let initialValue, fromValue(value.wrappedValue) != nil { value.wrappedValue = initialValue } customValueInputIsInvalid = !customValueInput.isEmpty @@ -355,18 +360,23 @@ struct SingleChoiceList<Value>: View where Value: Equatable { case three case someNumber(Int) } - return StatefulPreviewWrapper(ExampleValue.two) { SingleChoiceList( - title: "Test", - options: [.two, .three], - value: $0, - parseCustomValue: { Int($0).flatMap { $0 > 3 ? ExampleValue.someNumber($0) : nil } }, - formatCustomValue: { if case let .someNumber(n) = $0 { "\(n)" } else { nil } }, - customLabel: "Custom", - customPrompt: "Number", - customLegend: "The legend goes here", - customInputMinWidth: 120, - customInputMaxLength: 6, - customFieldMode: .numericText - ) + return StatefulPreviewWrapper(ExampleValue.two) { value in + VStack { + let vs = "Value = \(value.wrappedValue)" + Text(vs) + SingleChoiceList( + title: "Test", + options: [.two, .three], + value: value, + parseCustomValue: { Int($0).flatMap { $0 > 3 ? ExampleValue.someNumber($0) : nil } }, + formatCustomValue: { if case let .someNumber(n) = $0 { "\(n)" } else { nil } }, + customLabel: "Custom", + customPrompt: "Number", + customLegend: "The legend goes here", + customInputMinWidth: 120, + customInputMaxLength: 6, + customFieldMode: .numericText + ) + } } } |
