Skip to content

steps should be discrete offsets from lowerBound #71

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shuang886
Copy link

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)")
Screenshot 2023-09-18 at 9 58 09 AM

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.

- i.e., lowerBound = 3.5, step = 0.2, values should be 3.7, 3.9, etc.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant