alantoa / react-native-awesome-slider

🚀 An anwesome <Slider/> that supports various features haptic, lottie, animation, ballon, etc.
MIT License
228 stars 28 forks source link

Progress shows incorrect value when Step is set #52

Closed Nero15739 closed 6 months ago

Nero15739 commented 6 months ago

When ever I have a step assigned to the slider the progress does not correctly display on the slider as shown. The top number is the progress.value set at initialisation and the sliders have two different slider step counts 4 and 5 respectively.

Screenshot 2023-12-05 at 1 08 45 pm

I am using reanimation V3.5.4 and the latest version of react-native-awesome-slider; V2.5.4

Nero15739 commented 6 months ago

The problem seems like it's not the fault of the package but the useSharedValue() taking time to adopt the value even if done before rendering the slider with the updated values.

I found I could get around this issue by querying the data outside of the slider object then directly input the min, max, and value into the useSharedValue() to get around the slider not re-rendering or updating when progress.value is changed.

const AttributeSlider = ({ attributeName, attributeNames, attributeValue, callbackValue, minValue = 1, maxValue = 5, value = 1, }) => { console.log("Attribute Level ", attributeValue); const min = useSharedValue(minValue); const max = useSharedValue(maxValue); const progress = useSharedValue(value);

I hope if anyone else is also suffering from the same issue this can help you.