Skip to content

Instantly share code, notes, and snippets.

View dbismut's full-sized avatar
🏠
Working from home

David Bismut dbismut

🏠
Working from home
View GitHub Profile
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:11
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) {
@dbismut
dbismut / Post.js
Last active April 9, 2018 21:58
Part 3 - Adding onScroll listener to prepare for the drag feature
componentWillUnmount = () => {
this.removeListeners();
};
addListeners = () => {
window.addEventListener('scroll', this.onScroll);
};
removeListeners = () => {
window.removeEventListener('scroll', this.onScroll);
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:07
Part 2 - adding the .scroll-block class to the post node for the exiting transition
onExit = () => {
/* same code */
this.to = this.getPreviewStyleAndPosition();
const scrollTop = windowScroll.get('top');
this.post.classList.add('scroll-block');
this.postScroll.set('top', scrollTop);
};
@dbismut
dbismut / Post.js
Last active April 9, 2018 07:54
Part 2 - Setting onEnter function - referencing the preview node
onEnter = () => {
const { post } = this.props.route.data;
this.preview = document.querySelector(`.preview[data-id="${post.id}"]`);
this.pageList = document.querySelector('.page-list');
this.pageListStyler = styler(this.pageList);
this.from = this.getPreviewStyleAndPosition();
};
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:08
Part 2 - animating the scrollTop property separately during the exiting transition
executeExitingTransition = (node, done) => {
// we're temporarily changing our spring to
// a tween with a very long duration to check
// everything is working properly
tween({
from: this.from,
to: this.to,
duration: 10000
// stiffness: 100,
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:06
Part 2 - Adding scrollTop values to this.from and this.to
onExit = () => {
// we don't want to run this if there is no
// preview element to transition to.
if (!this.preview) return;
this.from = {
top: 0,
height: this.post.offsetHeight,
width: this.post.offsetWidth,
borderRadius: this.postStyler.get('borderRadius'),
@dbismut
dbismut / App.scss
Last active April 9, 2018 08:05
Part 2 - creating the scroll-block class to prevent the post from scroll glitch during exiting transition
.scroll-block {
position: fixed !important;
overflow: hidden !important;
max-height: 100vh !important;
pointer-events: none;
}
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:04
Part 2 - Animating the exiting transition
executeExitingTransition = (node, done) => {
spring({
from: this.from,
to: this.to,
stiffness: 100,
damping: 12,
restDelta: true,
restSpeed: 0.1
}).start({
update: this.postStyler.set,
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:03
Part 2 - Setting this.from and this.to for the exiting transition
onExit = () => {
// we don't want the code to run if there is no
// preview element to transition to.
if (!this.preview) return;
this.from = {
top: 0,
height: this.post.offsetHeight,
width: this.post.offsetWidth,
borderRadius: this.postStyler.get('borderRadius')
@dbismut
dbismut / Post.js
Last active April 9, 2018 21:19
Part 2 - Bootstrapping the exiting transition
onExit = () => {}
executeExitingTransition = (node, done) => {
// we're going to do some work in there!
done();
}
onAddEndListener = (node, done) => {
if (!this.preview) return done();