Created
December 7, 2018 13:03
-
-
Save smddzcy/c9045dce05bcdda67474ebeecfa10f62 to your computer and use it in GitHub Desktop.
Infinite swipe using react-swipeable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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