Skip to content

Commit aac6336

Browse files
committed
Merge branch 'IOS-953-shadowsocks-port-selector-bug'
2 parents 30733c7 + aa1b5a1 commit aac6336

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

ios/MullvadVPN/View controllers/Settings/SwiftUI components/SingleChoiceList.swift

+24-14
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,12 @@ struct SingleChoiceList<Value>: View where Value: Equatable {
272272
// this is not a valid value, so we fall back to the
273273
// initial value, showing the invalid-value state if
274274
// the field is not empty
275-
if let initialValue {
275+
// As `customValueIsFocused` takes a while to propagate, we
276+
// only reset the field to the initial value if it was previously
277+
// a custom value. Otherwise, blanking this field when the user
278+
// has selected another field will cause the user's choice to be
279+
// overridden.
280+
if let initialValue, fromValue(value.wrappedValue) != nil {
276281
value.wrappedValue = initialValue
277282
}
278283
customValueInputIsInvalid = !customValueInput.isEmpty
@@ -355,18 +360,23 @@ struct SingleChoiceList<Value>: View where Value: Equatable {
355360
case three
356361
case someNumber(Int)
357362
}
358-
return StatefulPreviewWrapper(ExampleValue.two) { SingleChoiceList(
359-
title: "Test",
360-
options: [.two, .three],
361-
value: $0,
362-
parseCustomValue: { Int($0).flatMap { $0 > 3 ? ExampleValue.someNumber($0) : nil } },
363-
formatCustomValue: { if case let .someNumber(n) = $0 { "\(n)" } else { nil } },
364-
customLabel: "Custom",
365-
customPrompt: "Number",
366-
customLegend: "The legend goes here",
367-
customInputMinWidth: 120,
368-
customInputMaxLength: 6,
369-
customFieldMode: .numericText
370-
)
363+
return StatefulPreviewWrapper(ExampleValue.two) { value in
364+
VStack {
365+
let vs = "Value = \(value.wrappedValue)"
366+
Text(vs)
367+
SingleChoiceList(
368+
title: "Test",
369+
options: [.two, .three],
370+
value: value,
371+
parseCustomValue: { Int($0).flatMap { $0 > 3 ? ExampleValue.someNumber($0) : nil } },
372+
formatCustomValue: { if case let .someNumber(n) = $0 { "\(n)" } else { nil } },
373+
customLabel: "Custom",
374+
customPrompt: "Number",
375+
customLegend: "The legend goes here",
376+
customInputMinWidth: 120,
377+
customInputMaxLength: 6,
378+
customFieldMode: .numericText
379+
)
380+
}
371381
}
372382
}

0 commit comments

Comments
 (0)