Skip to content

Instantly share code, notes, and snippets.

@reime005
Last active January 13, 2021 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reime005/1cab94194edddd2a0c2fff6f3aaad30c to your computer and use it in GitHub Desktop.
Save reime005/1cab94194edddd2a0c2fff6f3aaad30c to your computer and use it in GitHub Desktop.
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