SimformSolutionsPvtLtd / react-native-radial-slider

React Native component to select or highlight a specific value from a range of values 👌 ✨
MIT License
141 stars 14 forks source link

When I set props.step ={0.1} #42

Closed maxud3 closed 7 months ago

maxud3 commented 1 year ago

Hello! I need step to be 0.1. When I set props.step ={0.1} it only works when clicking on the arrows. When moving the slider, it doesn't work.

securitateaa commented 1 year ago

Hello. In useSilderAnimation.ts you can change

 setValue((prevState: number) => {
      prevValue.current = Math.round(
        Math.abs(nValue - prevState) > diff / 4 ? prevState : nValue
      );
      return Math.round(
        Math.abs(nValue - prevState) > diff / 4 ? prevState : nValue
      );
    });

with

 setValue((prevState) => {
    const roundedValue = parseFloat(nValue.toFixed(1));
    prevValue.current = Math.abs(roundedValue - prevState) > diff / 4 ? prevState : roundedValue;
    return Math.abs(roundedValue - prevState) > diff / 4 ? prevState : roundedValue;
});

and it will work with sub-units.