Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
1.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
rnosov committed Feb 26, 2018
1 parent 2bc587d commit d38ed31
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-reveal",
"version": "1.1.9-beta.1",
"version": "1.1.9",
"author": "Roman Nosov <rnosov@gmail.com>",
"description": "Really simple way to add reveal on scroll animation to your React app.",
"license": "MIT",
Expand Down
55 changes: 26 additions & 29 deletions src/RevealBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React from 'react';
import { string, object, number, bool, func, oneOfType, oneOf, shape, element } from 'prop-types';
import { namespace, ssr, disableSsr, globalHide, cascade, collapseend, fadeOutEnabled, raf } from './lib/globals';
//import Step from './lib/Step';
import throttle from './lib/throttle';
//import throttle from './lib/throttle';

const
inOut = shape({
Expand Down Expand Up @@ -79,6 +79,19 @@ class RevealBase extends React.Component {
// return { transitionGroup: null }; // allows for nested Transitions
//}

makeHandler(handler) {
const update = () => {
handler.call(this);
this.ticking = false;
};
return () => {
if (!this.ticking) {
raf(update);
this.ticking = true;
}
};
}

constructor(props, context) {
super(props, context);
this.isOn = 'when' in props ? !!props.when : true;
Expand All @@ -94,26 +107,14 @@ class RevealBase extends React.Component {
this.savedChild = false;
this.isListener = false;
this.isShown = false;

this.ticking = false;
const update = () => {
this.reveal();
this.ticking = false;
};

const requestTick = () => {
if (!this.ticking) {
raf(update);
this.ticking = true;
}
};

this.revealHandler = requestTick;
this.revealHandler = this.makeHandler(this.reveal);
this.resizeHandler = this.makeHandler(this.resize);
//this.revealHandler = myThrottle(this.reveal.bind(this, false));
//this.revealHandler = rafThrottle(this.reveal.bind(this, false));
//this.revealHandler = rafThrottle(throttle(this.reveal.bind(this, false), 66));
//this.revealHandler = throttle(rafThrottle(this.reveal.bind(this, false)), 66);
this.resizeHandler = throttle(this.resize.bind(this), 500);
//this.resizeHandler = throttle(this.resize.bind(this), 500);
this.saveRef = this.saveRef.bind(this);
}

Expand Down Expand Up @@ -286,10 +287,10 @@ class RevealBase extends React.Component {
unlisten() {
if (this.isListener) {
window.removeEventListener('scroll', this.revealHandler, { passive: true });
window.removeEventListener('orientationchange', this.revealHandler);
window.document.removeEventListener('visibilitychange', this.revealHandler);
window.document.removeEventListener('collapseend', this.revealHandler);
window.removeEventListener('resize', this.resizeHandler);
window.removeEventListener('orientationchange', this.revealHandler, { passive: true });
window.document.removeEventListener('visibilitychange', this.revealHandler, { passive: true });
window.document.removeEventListener('collapseend', this.revealHandler, { passive: true });
window.removeEventListener('resize', this.resizeHandler, { passive: true });
this.isListener = false;
}
if(this.onRevealTimeout)
Expand All @@ -309,10 +310,10 @@ class RevealBase extends React.Component {
if (!this.isListener) {
this.isListener = true;
window.addEventListener('scroll', this.revealHandler, { passive: true });
window.addEventListener('orientationchange', this.revealHandler);
window.document.addEventListener('visibilitychange', this.revealHandler);
window.document.addEventListener('collapseend', this.revealHandler);
window.addEventListener('resize', this.resizeHandler);
window.addEventListener('orientationchange', this.revealHandler, { passive: true });
window.document.addEventListener('visibilitychange', this.revealHandler, { passive: true });
window.document.addEventListener('collapseend', this.revealHandler, { passive: true });
window.addEventListener('resize', this.resizeHandler, { passive: true });
}
}

Expand Down Expand Up @@ -477,7 +478,6 @@ class RevealBase extends React.Component {
const child = this.getChild();
//if (this.props.disabled)
// return child;

if (typeof child.ref === 'function')
this.childRef = child.ref;
let
Expand All @@ -486,11 +486,8 @@ class RevealBase extends React.Component {
let
newClass = this.props.disabled ? className : `${ this.props.outEffect ? namespace : '' }${ this.state.className ? ' ' + this.state.className : '' }${ className ? ' ' + className : '' }`||void 0,
newStyle;

if (typeof this.state.style.animationName === 'function')
if (typeof this.state.style.animationName === 'function') // todo: needs refactotoring
this.state.style.animationName = this.state.style.animationName(!this.isOn ,this.props);


if (this.props.cascade && !this.props.disabled && children && this.state.style.animationName) {
newChildren = this.cascade(children);
newStyle = { ...style, opacity: 1 };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

export const namespace = 'react-reveal';//, is16 = parseInt(version, 10) >= 16;
export const defaults = { duration: 1000, delay: 0, count: 1, };
export const raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {window.setTimeout(callback, 1000 / 60);};
export const raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {window.setTimeout(callback, 66);};

export let
ssr = true,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/makeCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ function makeCarousel(WrappedComponent, config = {}) {
}

componentDidMount() {

//swipedetect(this.beforeNode, this.handleSwipe );
//swipedetect(this.afterNode, this.handleSwipe );
swipedetect(this.beforeNode, this.handleSwipe );
swipedetect(this.afterNode, this.handleSwipe );
}

render() {
Expand Down
26 changes: 13 additions & 13 deletions src/lib/swipedetect.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// credit: http://www.javascriptkit.com/javatutors/touchevents2.shtml
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}
//// credit: http://www.javascriptkit.com/javatutors/touchevents2.shtml
// var supportsPassive = false;
// try {
// var opts = Object.defineProperty({}, 'passive', {
// get: function() {
// supportsPassive = true;
// }
// });
// window.addEventListener("testPassive", null, opts);
// window.removeEventListener("testPassive", null, opts);
// } catch (e) {}
export default function swipedetect(el, callback){

var touchsurface = el,
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function swipedetect(el, callback){
startY = touchobj.pageY;
startTime = new Date().getTime(); // record time when finger first makes contact with surface
//e.preventDefault();
}, supportsPassive ? { passive: true } : false)
}, { passive: true })//supportsPassive ? { passive: true } : false)

//touchsurface.addEventListener('touchmove', function(e){
// e.preventDefault() // prevent scrolling when inside DIV
Expand All @@ -58,5 +58,5 @@ export default function swipedetect(el, callback){
}
handleswipe(swipedir)
//e.preventDefault()
}, supportsPassive ? { passive: true } : false)
}, { passive: true })//supportsPassive ? { passive: true } : false)
}

0 comments on commit d38ed31

Please sign in to comment.