alantoa / react-native-awesome-slider

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

Slider thumb jumps on initial render. #17

Closed owaiswiz closed 2 years ago

owaiswiz commented 2 years ago

https://github.com/alantoa/react-native-awesome-slider/blob/main/src/slide.tsx#L301

clamp is called with

Assume thumbWidth is the default (e.g 14). width.value is updated in the onLayout callback. So it's 0 from the initial render until onLayout is called.

Thus clamp() will be called with clamp(0,0, 0 - 14) => clamp(0,0,-14), which returns -14. So the thumb initially uses translateX: -14 and renders outside the left edge bound for the first few renders until width.value becomes available

Easiest/safe solution here would be to just change the third argument of the clamp fn from width.value - thumbWidth to Math.max(0, width.value - thumbWidth) or width.value ? width.value - thumbWidth : 0

Or alternatively return lower bound if lowerBound > upperBound in the clamp function, however I am not sure if that'll break other things which rely on the opposite behavior.

I don't notice it on my iPhone but can notice on my Android phone.


BTW This is a pretty great library. Thanks for your work on this! 🙏🏼

alantoa commented 2 years ago

Hi, @owaiswiz! Thanks for you found this issue! I've been busy lately, I'll look into it later! If you're interested in this lib, commit a PR for this and I'll review it, I will be very grateful!

owaiswiz commented 2 years ago

@alantoa Thank you. I created https://github.com/alantoa/react-native-awesome-slider/pull/18

alantoa commented 2 years ago

hey, @owaiswiz! thank you! release in v2.0.7!