Skip to content

Instantly share code, notes, and snippets.

@reime005
Created September 5, 2020 11:43
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/53626b084900dd7e72a93e391f020367 to your computer and use it in GitHub Desktop.
Save reime005/53626b084900dd7e72a93e391f020367 to your computer and use it in GitHub Desktop.
onEnd: (event, ctx) => {
// dragged 40 percent of the screen's width
const thresh = width * 0.4;
// how much the user moved the image horizontally
const diff = ctx.startX + event.translationX;
if (diff > thresh) {
// swiped right
onSnap({ right: true });
} else if (diff < -1 * thresh) {
// swiped left
onSnap({ right: false });
} else {
// no left or right swipe, so 'jump' back to the initial position
// withSpring is from 'react-native-reanimated'
x.value = withSpring(0);
y.value = withSpring(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment