Skip to content

Commit c3c92e9

Browse files
dstdnkdeorst
andauthored
Fixed rounding problem, the cause of issue. (#280)
Co-authored-by: Dmitry Stadnik <[email protected]>
1 parent c257d6d commit c3c92e9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ios/RNCSliderManager.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,22 @@ - (void)tapHandler:(UITapGestureRecognizer *)gesture {
7979
static float discreteValue(RNCSlider *sender, float value) {
8080
// If step is set and less than or equal to difference between max and min values,
8181
// pick the closest discrete multiple of step to return.
82+
8283
if (sender.step > 0 && sender.step <= (sender.maximumValue - sender.minimumValue)) {
84+
85+
// Round up when increase, round down when decrease.
86+
double (^_round)(double) = ^(double x) {
87+
if (sender.lastValue > value) {
88+
return floor(x);
89+
} else {
90+
return ceil(x);
91+
}
92+
};
93+
8394
return
8495
MAX(sender.minimumValue,
8596
MIN(sender.maximumValue,
86-
sender.minimumValue + round((value - sender.minimumValue) / sender.step) * sender.step
97+
sender.minimumValue + _round((value - sender.minimumValue) / sender.step) * sender.step
8798
)
8899
);
89100
}

0 commit comments

Comments
 (0)