I want to use the Stepper view in manual (not binding) mode using onIncrement and onDecrement. There's a strange behavior when I try to implement lower and upper bounds, eg. having an age value not going bellow 1 or above 10.
If you try the bellow code, you can press "-" two times after it already has the value "1". It doesn't go bellow 1 as expected, but after the two additional presses the "-" button suddenly gets disabled. If you then press "+" nothing happens. Only after 2 additional presses to "+" the counter reacts as expected and goes to 2.
Is this a bug?
struct StepperTest: View {
@State private var age = 5
var body: some View {
VStack {
Stepper("Enter your age", onIncrement: {
if self.age < 10 {
self.age += 1
print("Adding to age")
}
}, onDecrement: {
guard self.age > 1 else { return }
self.age -= 1
print("Subtracting from age")
})
Text("Your age is \(age)")
}
}
}
editingChange
already and you can detect witch key is touched. What else do you need? – Corneliacornelian