Last active
April 9, 2018 21:58
-
-
Save dbismut/ef06f3c255b679e9f586a8ed1672a525 to your computer and use it in GitHub Desktop.
Part 3 - Adding onScroll listener to prepare for the drag feature
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
componentWillUnmount = () => { | |
this.removeListeners(); | |
}; | |
addListeners = () => { | |
window.addEventListener('scroll', this.onScroll); | |
}; | |
removeListeners = () => { | |
window.removeEventListener('scroll', this.onScroll); | |
}; | |
onScroll = () => { | |
const scrollTop = windowScroll.get('top'); | |
console.log(scrollTop); | |
}; | |
onEntered = () => { | |
// we add listeners as soon as the transition is complete | |
// we don't add them before to avoid them interfering | |
// with our post while animating | |
this.addListeners(); | |
}; | |
onExit = () => { | |
this.removeListeners(); | |
// we don't want to run this if there is no | |
// preview element to transition to. | |
if (!this.preview) return; | |
/* same code */ | |
} | |
render() { | |
/* same code */ | |
return ( | |
<CSSTransition | |
{...transitionProps} | |
onEnter={this.onEnter} | |
onEntered={this.onEntered} // add this | |
onExit={this.onExit} | |
addEndListener={this.onAddEndListener} | |
classNames="post" | |
> | |
/* same code */ | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment