Skip to content

Instantly share code, notes, and snippets.

@reime005

reime005/rn-animated-star-rating-7.js Secret

Last active Jan 13, 2021
Embed
What would you like to do?
const changeOffset = React.useCallback((e: GestureResponderEvent) => {
const { nativeEvent } = e;
const distance = (screenWidth - animatedWidth.current) / 2; // view is centered
const starSize = animatedWidth.current / 5; // 5 stars
let starVal = Number((nativeEvent.pageX - distance) / starSize);
const rest = starVal - Math.trunc(starVal);
if (rest <= 0.5) {
starVal = Math.trunc(starVal);
} else {
starVal = Math.trunc(starVal) + 0.5;
}
setOffset(starVal);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment