Skip to content

Instantly share code, notes, and snippets.

@dbismut
Last active April 9, 2018 08:11
Show Gist options
  • Save dbismut/a31c7cb81e15cac4ae127a5cdb734d07 to your computer and use it in GitHub Desktop.
Save dbismut/a31c7cb81e15cac4ae127a5cdb734d07 to your computer and use it in GitHub Desktop.
Part 3 - Creates onScroll method and related state to prepare for the drag feature
class Post extends PureComponent {
state = {
dragProgress: 0
}
/* ... */
onScroll = () => {
const scrollTop = windowScroll.get('top');
if (scrollTop < 0 && !this.isTransitioningFromDrag) {
if (scrollTop > -DRAG_THRESHOLD) {
const dragProgress = Math.min(1, -scrollTop / DRAG_LIMIT);
this.setState({ dragProgress });
} else {
this.isTransitioningFromDrag = true;
this.props.navigateTo('home');
}
return;
}
this.setState({ dragProgress: 0 });
};
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment