material-components / material-components/material-components-android
[Slider] Handle invalid values more controllably
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
My app uses Slider as a drop-in replacement for SeekBar. However, the values that Slider could be given could be invalid. valueTo < value, value < 0, etc. I have no control over the validity of these values as they are usually the result of race conditions or OS quirks.
However, Slider crashes with invalid values. This makes sense considering that slider is likely designed for configuration use cases, which tend to not have very dynamic values. In my app however, this causes a variety of crashes when invalid input bleeds through. Worse still, this crash occurs at draw-time, which prevents me from recovering from invalid Slider values until it's too late.
Instead I'm required to sanitize incoming input to the Slider, which is hard to maintain and could still lead to crashes if I forget to check for a particular case.
Describe the solution you'd like
Throw an exception when you update the values (setValueTo, setValue, etc.) instead of throwing an exception at draw-time. This would allow me to catch invalid values and simply not update the slider until the values become valid, which will happen eventually.
Alternatively, Slider could gracefully degrade with invalid values, like SeekBar. I'd imagine this would not be as ideal for debugging however, so the first option is the most viable I think.
Describe alternatives you've considered
As I mentioned, I currently try to sanitize incoming values, which is fallible and hard to maintain on my end.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Slider's setValueTo, setValue, and related value-update entry points to see where invalid values are currently accepted and where the draw-time crash occurs. Done means invalid inputs are handled during the update rather than first failing during drawing, with coverage for cases such as valueTo < value and value < 0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100