Skip to content

Commit 1f8a079

Browse files
* Thumbs are now updated when low or high value is set
1 parent 43aeefb commit 1f8a079

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

hooks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const useLowHigh = (lowProp, highProp, min, max, step) => {
2323
const validHighProp = highProp === undefined ? max : clamp(highProp, min, max);
2424
const inPropsRef = useRef({ low: validLowProp, high: validHighProp });
2525
const { low: lowState, high: highState } = inPropsRef.current;
26+
const inPropsRefPrev = { lowPrev: lowState, highPrev: highState };
2627

2728
// Props have higher priority.
2829
// If no props are passed, use internal state variables.
@@ -34,7 +35,7 @@ export const useLowHigh = (lowProp, highProp, min, max, step) => {
3435

3536
const setLow = value => inPropsRef.current.low = value;
3637
const setHigh = value => inPropsRef.current.high = value;
37-
return { inPropsRef, setLow, setHigh };
38+
return { inPropsRef, inPropsRefPrev, setLow, setHigh };
3839
};
3940

4041
/**

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Slider = (
2929
...restProps
3030
}
3131
) => {
32-
const { inPropsRef, setLow, setHigh } = useLowHigh(lowProp, disableRange ? max : highProp, min, max, step);
32+
const { inPropsRef, inPropsRefPrev, setLow, setHigh } = useLowHigh(lowProp, disableRange ? max : highProp, min, max, step);
3333
const lowThumbXRef = useRef(new Animated.Value(0));
3434
const highThumbXRef = useRef(new Animated.Value(0));
3535
const pointerX = useRef(new Animated.Value(0)).current;
@@ -63,11 +63,11 @@ const Slider = (
6363
}, [disableRange, inPropsRef, max, min, onValueChanged, thumbWidth, updateSelectedRail]);
6464

6565
useEffect(() => {
66-
const { low, high } = inPropsRef.current;
67-
if ((lowProp !== undefined && lowProp !== low) || (highProp !== undefined && highProp !== high)) {
66+
const { lowPrev, highPrev } = inPropsRefPrev;
67+
if ((lowProp !== undefined && lowProp !== lowPrev) || (highProp !== undefined && highProp !== highPrev)) {
6868
updateThumbs();
6969
}
70-
}, [highProp, inPropsRef, lowProp]);
70+
}, [highProp, inPropsRefPrev.lowPrev, inPropsRefPrev.highPrev, lowProp]);
7171

7272
useEffect(() => {
7373
updateThumbs();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rn-range-slider",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"author": "Tigran Sahakyan <mail.of.tigran@gmail.com>",
55
"description": "A highly optimized pure JS implementation of Range Slider for React Native",
66
"homepage": "https://github.com/githuboftigran/rn-range-slider",

0 commit comments

Comments
 (0)