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

Commit

Permalink
ssr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rnosov committed Feb 21, 2018
1 parent db4fe69 commit cf0cfca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# React Reveal

[React Reveal](https://www.react-reveal.com/) is
an attention management framework for React. It's MIT licensed, has a tiny footprint
an animation framework for React. It's MIT licensed, has a tiny footprint
and written specifically for React in ES6. It can be used to create various cool reveal
on scroll animations in your application.
If you liked this package, don't forget to star
Expand Down
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.5",
"version": "1.1.6-beta.2",
"author": "Roman Nosov <rnosov@gmail.com>",
"description": "Really simple way to add reveal on scroll animation to your React app.",
"license": "MIT",
Expand Down
15 changes: 10 additions & 5 deletions src/RevealBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RevealBase extends React.Component {
this.state = {
collapse: props.collapse ? RevealBase.getInitialCollapseStyle(props): void 0,
style: {
opacity: !this.isOn && props.outEffect ? 0 : void 0,
opacity: (!this.isOn||props.always) && props.outEffect ? 0 : void 0,
//visibility: props.when ? 'visible' : 'hidden',
},
};
Expand Down Expand Up @@ -211,7 +211,7 @@ class RevealBase extends React.Component {
//const inOut = props[this.isOn || !props.outEffectEffect ?'inEffect':'outEffect'];
let animationName = (('style' in inOut) && inOut.style.animationName) || void 0;
if ((props.outEffect||this.isOn) && inOut.make)
animationName = inOut.make();
animationName = this.animationName || inOut.make();
let state = {/* status: leaving ? 'exiting':'entering',*/
hasAppeared: true,
hasExited: false,
Expand Down Expand Up @@ -283,6 +283,8 @@ class RevealBase extends React.Component {
if (!this||!this.el) return;
if (!props)
props = this.props;
if (ssr)
disableSsr();
if ( this.isOn && this.isShown && 'spy' in props ){
this.isShown = false;
this.setState({ style: {} });
Expand All @@ -302,10 +304,12 @@ class RevealBase extends React.Component {
componentDidMount() {
if (!this.el || this.props.disabled)
return;
if ('make' in this.props)
this.animationName = this.props.inEffect.make();
const parentGroup = this.context.transitionGroup;
const appear = parentGroup && !parentGroup.isMounting ? !('enter' in this.props && this.props.enter === false) : this.props.appear;
if (this.isOn && ((('when' in this.props || 'spy' in this.props) && !appear)
|| (ssr && !fadeOutEnabled && this.props.outEffect && (RevealBase.getTop(this.el) < window.pageYOffset + window.innerHeight)))
|| (ssr && !fadeOutEnabled && this.props.outEffect && !this.props.always && (RevealBase.getTop(this.el) < window.pageYOffset + window.innerHeight)))
) {
this.isShown = true;
this.setState({
Expand Down Expand Up @@ -364,8 +368,9 @@ class RevealBase extends React.Component {

static getInitialCollapseStyle(props) {
return {
//height: ismounting ? void 0 : 0,
height: 0,
visibility: props.when ? 'visible' : 'hidden',
visibility: props.when ? void 0 : 'hidden',
//height: props.when ? void 0 : 0,
//padding: 0,
//border: 0,
Expand Down Expand Up @@ -453,6 +458,6 @@ class RevealBase extends React.Component {
RevealBase.propTypes = propTypes;
RevealBase.defaultProps = defaultProps;
RevealBase.contextTypes = contextTypes;
//RevealBase.displayName = 'RevealBase';
RevealBase.displayName = 'RevealBase';
//RevealBase.childContextTypes = childContextTypes;
export default RevealBase;
2 changes: 1 addition & 1 deletion src/lib/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if (typeof window !== 'undefined' && window.name !== 'nodejs' && window.document
&& 'timing' in window.performance
&& 'domContentLoadedEventEnd' in window.performance.timing
&& window.performance.timing.domLoading
&& Date.now() - window.performance.timing.domLoading<500)
&& Date.now() - window.performance.timing.domLoading<300)
ssr = false;
collapseend = document.createEvent('Event');
collapseend.initEvent('collapseend', true, true);
Expand Down
14 changes: 8 additions & 6 deletions src/lib/makeCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ function makeCarousel(WrappedComponent, config = {}) {
current: 0,
next: 1,
backwards: false,
swap: false
swap: false,
appear: false,
};
this.turn = 0;
this.handleReveal = this.handleReveal.bind(this);
this.handleSwipe = this.handleSwipe.bind(this);
this.target = this.target.bind(this);
}

target({target}) {
this.move(+target.getAttribute('data-position'));
target({currentTarget}) {
this.move(+currentTarget.getAttribute('data-position'));
}

handleReveal() {
Expand Down Expand Up @@ -78,7 +79,8 @@ function makeCarousel(WrappedComponent, config = {}) {
current: pos,
next: this.state.current,
backwards: newPos<this.state.current,
swap: !this.state.swap
swap: !this.state.swap,
appear: true,
});
}

Expand Down Expand Up @@ -119,7 +121,7 @@ function makeCarousel(WrappedComponent, config = {}) {
<before.type
mountOnEnter
unmountOnExit
appear
appear={this.state.appear}
wait={this.props.defaultWait}
{...before.props}
opposite
Expand All @@ -132,7 +134,7 @@ function makeCarousel(WrappedComponent, config = {}) {
<after.type
mountOnEnter
unmountOnExit
appear
appear={this.state.appear}
wait={this.props.defaultWait}
{...after.props}
opposite
Expand Down

0 comments on commit cf0cfca

Please sign in to comment.