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
Created April 9, 2018 09:49
Part 2 - Fixing one last glitch
/* other imports */
import browser from 'bowser'; // the browser import
/* ... */
executeEnteringTransition = (node, done) => {
this.postStyler.set({ ...this.from, visibility: 'visible' });
const hidePreview = () => (this.preview.style.visibility = 'hidden');
@dbismut
dbismut / Post.scss
Last active April 9, 2018 22:13
Part 3 - Styling the underlay so it gets a blur
.page-post .underlay {
position: fixed;
top: -10vh;
left: 0;
z-index: 0;
width: 100vw;
height: 120vh;
background-color: #fff;
transition: opacity 400ms ease;
&::before {
@dbismut
dbismut / Post.js
Created April 9, 2018 09:04
Part 3 - Creating the underlay div
/* ... */
<div
className={cn('page full-width page-post', {
'post-dragged': dragProgress > 0
})}
>
<div className="underlay" />
<div
ref={post => (this.post = post)}
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:10
Part 3 - onScroll update to prevent elastic inertia
onScroll = () => {
const scrollTop = windowScroll.get('top');
if (scrollTop < 0 && !this.isTransitioningFromDrag) {
if (this.isTouching) this.isDragging = true;
if (this.isDragging) {
if (scrollTop > -DRAG_THRESHOLD) {
const dragProgress = Math.min(1, -scrollTop / DRAG_LIMIT);
this.setState({ dragProgress });
} else {
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:10
Part 3 - Adding listeners for touch events
addListeners = () => {
window.addEventListener('scroll', this.onScroll);
window.addEventListener('touchstart', this.onTouchStart);
window.addEventListener('touchend', this.onTouchEnd);
};
removeListeners = () => {
window.removeEventListener('scroll', this.onScroll);
window.removeEventListener('touchend', this.onTouchEnd);
window.removeEventListener('touchstart', this.onTouchStart);
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:10
Part 3 - Fixes close icon fixed position after entering transition
executeEnteringTransition = (node, done) => {
/* same code */
complete: () => {
tween({ from: windowScroll.get('top'), to: 0 }).start({
update: v => windowScroll.set('top', v),
complete: () => {
// this removes all style from the post node
// and fixes the close icon position bug
// https://stackoverflow.com/questions/42660332/css-transform-parent-and-fixed-child-is-there-a-way-to-breakout-of-node-with-tr
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:10
Part 3 - Toggle .post-dragged class when dragProgress is greater than null
<div className={cn('page full-width page-post', { 'post-dragged': dragProgress > 0 })}>
@dbismut
dbismut / Post.js
Last active April 9, 2018 08:10
Part 3 - Adding scale to transition from drag and compensate viewport scroll in this.to
onExit = () => {
this.removeListeners();
if (!this.preview) return;
const scale = 1 - this.state.dragProgress * (1 - DRAG_MINIMUM_SCALE);
this.from = {
top: 0,
height: this.post.offsetHeight,
width: this.post.offsetWidth,
@dbismut
dbismut / Post.scss
Last active April 9, 2018 22:02
Part 3 - Creation of CSS rule .post-dragged
// .post-dragged rule is exactly the same
// as .post-enter
.page-post {
&.post-enter,
&.post-dragged { // add this rule
.post {
position: fixed;
overflow: hidden;
pointer-events: none;
}
@dbismut
dbismut / Post.js
Last active April 9, 2018 22:01
Part 3 - Scales the post node in render according to dragProgress
render() {
/* same code */
const { dragProgress } = this.state;
const postStyle =
dragProgress > 0
? {
transform: `scale(${1 - dragProgress * (1 - DRAG_MINIMUM_SCALE)})`,
borderRadius: dragProgress * 16