swiftui-sliders
swiftui-sliders copied to clipboard
steps should be discrete offsets from lowerBound
Given:
Slider(value: $v1, in: 1...10, step: 2, onEditingChanged: { _ in })
Text("Slider: \(v1)")
ValueSlider(value: $v2, in: 1...10, step: 2, onEditingChanged: { _ in })
.frame(height: 30)
Text("ValueSlider: \(v2)")
Apple's Slider() reports the discrete values [ 1, 3, 5, 7, 9 ] while ValueSlider() reports [ 1, 2, 4, 6, 8, 10 ]. IOW, Slider()'s steps are offsets from the lowerBound while ValueSlider()'s are 0-based.
This PR changes the behavior of step to match Slider().
Note: even with this fix, ValueSlider() will report [ 1, 3, 5, 7, 9, 10 ] even though the upperBound value is not a multiple of step. That's easily worked around by client code if desired, so I'm not sure it should be fixed.