From 69dc7714197c929d95c269500e6e002f079abc5d Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Mon, 18 Oct 2021 23:28:50 +0200 Subject: [PATCH 1/2] Check if targeted value exceeds the range --- src/ios/RNCSliderManager.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ios/RNCSliderManager.m b/src/ios/RNCSliderManager.m index 75b791b2..9f7cb46e 100644 --- a/src/ios/RNCSliderManager.m +++ b/src/ios/RNCSliderManager.m @@ -77,9 +77,12 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture { } static float discreteValue(RNCSlider *sender, float value) { + if (sender.step > 0 && value >= sender.maximumValue) { + return sender.maximumValue + } + // If step is set and less than or equal to difference between max and min values, // pick the closest discrete multiple of step to return. - if (sender.step > 0 && sender.step <= (sender.maximumValue - sender.minimumValue)) { // Round up when increase, round down when decrease. From ca9a7edf71414b1f839c050ff85a61aa263ac277 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Mon, 18 Oct 2021 23:49:48 +0200 Subject: [PATCH 2/2] Cover the check with comment explaining its purpose --- src/ios/RNCSliderManager.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ios/RNCSliderManager.m b/src/ios/RNCSliderManager.m index 9f7cb46e..8722a373 100644 --- a/src/ios/RNCSliderManager.m +++ b/src/ios/RNCSliderManager.m @@ -77,8 +77,10 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture { } static float discreteValue(RNCSlider *sender, float value) { + // Check if thumb should reach the maximum value and put it on the end of track if yes. + // To avoid affecting the thumb when on maximum, the `step >= (value - maximum)` is not checked. if (sender.step > 0 && value >= sender.maximumValue) { - return sender.maximumValue + return sender.maximumValue; } // If step is set and less than or equal to difference between max and min values,