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

[Slider] java.lang.IllegalStateException: valueFrom(2.0) must be smaller than valueTo(2.0) #2787

Open
amitlodha opened this issue Jun 28, 2022 · 9 comments · May be fixed by #4257
Open

[Slider] java.lang.IllegalStateException: valueFrom(2.0) must be smaller than valueTo(2.0) #2787

amitlodha opened this issue Jun 28, 2022 · 9 comments · May be fixed by #4257

Comments

@amitlodha
Copy link

Description:
When i set value to slider having same valueTo and ValueFrom it crash

Crash Logs:
java.lang.IllegalStateException: valueFrom(2.0) must be smaller than valueTo(2.0)
at com.google.android.material.slider.BaseSlider.validateValueFrom(BaseSlider.java:520)
at com.google.android.material.slider.BaseSlider.validateConfigurationIfDirty(BaseSlider.java:608)
at com.google.android.material.slider.BaseSlider.onDraw(BaseSlider.java:1662)
at android.view.View.draw(View.java:22644)
at android.view.View.updateDisplayListIfDirty(View.java:21519)

Suggestion:
We should not throw exception instead we should accept the same value

private void validateValueFrom() {
if (valueFrom >= valueTo) {
throw new IllegalStateException(
String.format(EXCEPTION_ILLEGAL_VALUE_FROM, valueFrom, valueTo));
}
}

private void validateValueTo() {
if (valueTo <= valueFrom) {
throw new IllegalStateException(
String.format(EXCEPTION_ILLEGAL_VALUE_TO, valueTo, valueFrom));
}
}

@amitlodha amitlodha added the bug label Jun 28, 2022
@drchen
Copy link
Contributor

drchen commented Jun 28, 2022

It's WAI. It's illegal to have the same ValueTo and ValueFrom. (There's no sliding range in this case.)

@drchen drchen closed this as completed Jun 28, 2022
@amitlodha
Copy link
Author

amitlodha commented Jun 28, 2022

Hi @drchen We are using slider in our search and sometime we do get only 1 result or we doing search with result having same price as we do sliding on price, there will have same value because of same price.

@drchen
Copy link
Contributor

drchen commented Jun 28, 2022

hmm.. That's a fair point. Let me talk to the team for their opinion.

@amitlodha
Copy link
Author

@drchen Any Update on same?

@drchen
Copy link
Contributor

drchen commented Jun 30, 2022

Hi I'm going to reopen this as a feature request. But we need to make sure the rest of the logic works in this case, so it may take us some time to implement.

@akhbulatov
Copy link

@drchen any update on this feature?

@akhbulatov
Copy link

@drchen due to the fact that it is impossible to assign the same values from and to, which come from backend, we have to do some ugly workaround. This fix would be very useful.

@pubiqq @manabu-nakamura guys, maybe you could fix this bug? :)

@manabu-nakamura
Copy link
Contributor

Google seems to be accepting very few contributions these days...

@akhbulatov
Copy link

@manabu-nakamura even if a PR is not accepted, anyone who wants this fix can take the changes from the PR. I tried to copy BaseSlider to myself and change the condition, but the slider did not work correctly after that

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