Skip to content

iOS Slider Discrete Values Issue #394

Open
@dangrima90

Description

@dangrima90

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:

[maxValueProperty.setNative](value) {
this.nativeViewProtected.maximumValue = value;
if (this.stepSize !== 0) {
this.nativeViewProtected.numberOfDiscreteValues = (this.maxValue - this.minValue) / value;
}
}

[stepSizeProperty.setNative](value) {
if (value === 0) {
this.nativeViewProtected.discrete = false;
} else {
this.nativeViewProtected.discrete = true;
this.nativeViewProtected.numberOfDiscreteValues = (this.maxValue - this.minValue) / value;
this.nativeViewProtected.shouldDisplayDiscreteValueLabel = false;
}
}

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;
  },
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions