Skip to content

Instantly share code, notes, and snippets.

@smddzcy
Created December 7, 2018 13:03
Show Gist options
  • Save smddzcy/c9045dce05bcdda67474ebeecfa10f62 to your computer and use it in GitHub Desktop.
Save smddzcy/c9045dce05bcdda67474ebeecfa10f62 to your computer and use it in GitHub Desktop.
Infinite swipe using react-swipeable
onColorSwipe = (e, dx, dy, absX, absY, v) => {
const h = this.colorScroller.scrollHeight;
this.setState(state => {
const top = state.colorScrollerTop + state.colorScrollerDy;
if (-top > h * 4 / 5) { // almost at the end
return { colorScrollerTop: state.colorScrollerTop + h / 3, colorScrollerDy: -dy };
}
if (-top < h / 5) { // almost at the beginning
return { colorScrollerTop: state.colorScrollerTop - h / 3, colorScrollerDy: -dy };
}
return { colorScrollerDy: -dy };
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment