Skip to content

Commit 76e2052

Browse files
authored
Merge pull request #395 from dangrima90/fix/ios-slider-number-of-discrete-values
iOS Slider numberOfDiscreteValues fix
2 parents f889849 + 7abb644 commit 76e2052

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/slider/slider.ios.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ export class Slider extends SliderBase {
6565
[minValueProperty.setNative](value) {
6666
this.nativeViewProtected.minimumValue = value;
6767
if (this.stepSize !== 0) {
68-
this.nativeViewProtected.numberOfDiscreteValues = (this.maxValue - this.minValue) / value;
68+
// add one to get amount of values and not difference between min and max
69+
const valuesCount = this.maxValue - this.minValue + 1;
70+
this.nativeViewProtected.numberOfDiscreteValues = Math.ceil(valuesCount / value);
6971
}
7072
}
7173
[maxValueProperty.setNative](value) {
7274
this.nativeViewProtected.maximumValue = value;
7375
if (this.stepSize !== 0) {
74-
this.nativeViewProtected.numberOfDiscreteValues = (this.maxValue - this.minValue) / value;
76+
// add one to get amount of values and not difference between min and max
77+
const valuesCount = this.maxValue - this.minValue + 1;
78+
this.nativeViewProtected.numberOfDiscreteValues = Math.ceil(valuesCount / value);
7579
}
7680
}
7781
[stepSizeProperty.getDefault]() {
@@ -82,7 +86,11 @@ export class Slider extends SliderBase {
8286
this.nativeViewProtected.discrete = false;
8387
} else {
8488
this.nativeViewProtected.discrete = true;
85-
this.nativeViewProtected.numberOfDiscreteValues = (this.maxValue - this.minValue) / value;
89+
90+
// add one to get amount of values and not difference between min and max
91+
const valuesCount = this.maxValue - this.minValue + 1;
92+
this.nativeViewProtected.numberOfDiscreteValues = Math.ceil(valuesCount / value);
93+
8694
this.nativeViewProtected.shouldDisplayDiscreteValueLabel = false;
8795
}
8896
}

0 commit comments

Comments
 (0)