Description
I think I've found a bug with how the numberOfDiscreteValues
is being calculated for iOS. I'm currently using @nativescript-community/[email protected]
I have the following example:
Min Value: 1000
Max Value: 10000
Step Size: 1000
When debugging I've noticed that numberOfDiscreteValues
is being to set to 9 instead of 10. This is resulting in a continuous slider rather than a discrete one. From what I'm seeing the calculation is a difference of max and min, rather than the number of values.
Here the calculation:
ui-material-components/src/slider/slider.ios.ts
Lines 71 to 76 in f889849
ui-material-components/src/slider/slider.ios.ts
Lines 80 to 88 in f889849
With the above logic the numberOfDiscreteValues
is one less than the correct value.
I'm not blocked with the issue as I'm setting the numberOfDiscreteValues
myself. I'm using NativeScript-Vue, here's a sample logic that is working for me:
computed: {
totalTickMarks() {
/**
* adding one as the number of ticks represents the number of values and not the difference
* Example Range: 0 to 10 = 11 ticks; Therefore: 10 - 0 + 1 = 11
* Example Range: 5 to 50 = 46 ticks; Therefore: 50 - 5 + 1 = 46
*/
const tickMarksCount = this.maxValue - this.minValue + 1;
if (this.stepSize) {
// always set value to whole number after dividing
return Math.ceil(tickMarksCount / this.stepSize);
}
return tickMarksCount;
}
},
// ...
methods: {
sliderLoad() {
const nativeView = this.$refs.slider.nativeView.ios;
nativeView.numberOfDiscreteValues = this.totalTickMarks;
},
},