diff --git a/index.js b/index.js index c054f07..399cdae 100644 --- a/index.js +++ b/index.js @@ -28,10 +28,11 @@ const Slider = ( renderNotch, renderRail, renderRailSelected, + value, ...restProps } ) => { - const { inPropsRef, inPropsRefPrev, setLow, setHigh } = useLowHigh(lowProp, disableRange ? max : highProp, min, max, step); + const { inPropsRef, inPropsRefPrev, setLow, setHigh } = useLowHigh(value ?? lowProp, disableRange ? max : highProp, min, max, step); const lowThumbXRef = useRef(new Animated.Value(0)); const highThumbXRef = useRef(new Animated.Value(0)); const pointerX = useRef(new Animated.Value(0)).current; @@ -47,6 +48,7 @@ const Slider = ( const [selectedRailStyle, updateSelectedRail] = useSelectedRail(inPropsRef, containerWidthRef, thumbWidth, disableRange); const updateThumbs = useCallback(() => { + const { lowPrev, highPrev } = inPropsRefPrev; const { current: containerWidth } = containerWidthRef; if (!thumbWidth || !containerWidth) { return; @@ -61,8 +63,10 @@ const Slider = ( const lowPosition = (low - min) / (max - min) * (containerWidth - thumbWidth); lowThumbX.setValue(lowPosition); updateSelectedRail(); - onValueChanged?.(low, high, false); - }, [disableRange, inPropsRef, max, min, onValueChanged, thumbWidth, updateSelectedRail]); + if ((lowProp !== undefined && lowProp !== lowPrev) || (highProp !== undefined && highProp !== highPrev)) { + onValueChanged?.(low, high, false); + } + }, [disableRange, inPropsRef, max, min, onValueChanged, thumbWidth, updateSelectedRail,highProp, inPropsRefPrev.lowPrev, inPropsRefPrev.highPrev, lowProp]); useEffect(() => { const { lowPrev, highPrev } = inPropsRefPrev; @@ -221,6 +225,7 @@ Slider.propTypes = { onValueChanged: PropTypes.func, onTouchStart: PropTypes.func, onTouchEnd: PropTypes.func, + value:PropTypes.number }; Slider.defaultProps = { diff --git a/package.json b/package.json index 10ba75e..e33444c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rn-range-slider", - "version": "2.1.1", + "version": "2.1.2", "author": "Tigran Sahakyan ", "description": "A highly optimized pure JS implementation of Range Slider for React Native", "homepage": "https://github.com/githuboftigran/rn-range-slider",