Anyone experienced this.
My goal is to use AppStorage to save the value in the stepper but the behavior is whaked. Buttons get disabled even when theyre not at both ends of the array
if i use State, it works a bit better but the buttons only get disabled after the 2nd or 3rd try when the index is either 0 or at the end of the array.
@AppStorage("index") private var opacity = 0
let options = [40, 50, 70, 80, 90, 100]
Stepper {
Text("\("Opacity") \(options[opacity].description)%")
} onIncrement: {
opacity = opacity + 1
if opacity >= opacity.count {
opacity = opacity.count - 1
}
print("onincrement="+String(opacity))
} onDecrement: {
opacity = opacity - 1
if opacity < 0 {
opacity = 0
}
print("ondecrement="+String(opacity))
}
The sample code looks simple. I am not sure what else I could be missing?