Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Setting CurrentValue programmatically is not updating UI when minimum value is more than 0. #35

Open
LReema opened this issue Mar 25, 2023 · 3 comments
Labels

Comments

@LReema
Copy link

LReema commented Mar 25, 2023

Descrepencies when trying to set current Values of the slider.
I have set following values: maxRotationAngle: 270, minimumValue: 50.0, maximumValue: 90.0, currentValue = 62, programmatically.
When I query the currentValue it returns me 21.8.... and when I query the angle it gives 147.
My calculations are: when starting from Minimum, when reaching 70(middle of max and min) currentValue the angle should be 270/2= 135. So, for 62 angle should be less than 135.
Could you please correct me if I am missing something or provide a fix if this is not working fine?
This is urgent request.
The slider works great, for changing the slider value on UI.

@ThunderStruct
Copy link
Owner

ThunderStruct commented Mar 25, 2023

Hi,

I haven't had the time to maintain this framework, unfortunately. I did have a look for you nonetheless, and it does seem to be a bug.

Basically, the currentValue and angle setters use two internal conversion functions valueFrom(angle) and angleFrom(value). I seem to have not accounted for the minimumValue being non-zero.

Since you urgently need this fixed, change the functions (at the bottom of the MSCircularSlider.swift file) to the following and it should work as expected:

    /** Calculates the angle from north given a value */
    internal func angleFrom(value: Double) -> CGFloat {
        // added "- minimumValue" to the numerator
        return (CGFloat(value - minimumValue) * maximumAngle) / CGFloat(maximumValue - minimumValue)
    }

    /** Calculates the value given an angle from north */
    internal func valueFrom(angle: CGFloat) -> Double {
        // added "+ minimumValue"
        return (maximumValue - minimumValue) * Double(angle) / Double(maximumAngle) + minimumValue
    }

I will try to update the pod and the repo accordingly within the week, just need to make sure this actually works for other edge-cases.

If you have the time to apply this and test it properly, please fork the repo and submit a PR, you'll be added as a contributor.

@LReema
Copy link
Author

LReema commented Mar 27, 2023

Thank you for the quick response. The fix works fine when minimum value is set.

@LReema
Copy link
Author

LReema commented Mar 27, 2023

I am unable to create a new PR as code is same.
The changes are fine for all the conditions.
I tried with different maximum angles - 90,180,270,360 and different minimum and maximum values.
Changing the values in UI and programmatically to the slider looks fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants