Skip to content

Instantly share code, notes, and snippets.

@reime005
Last active January 13, 2021 13:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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