Last active
June 29, 2016 23:39
-
-
Save gtwalford/65144ca0a9e4970867d1000b6e4b836e to your computer and use it in GitHub Desktop.
Velocity registerEffects w/ server-side React
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
import React from 'react'; | |
import { VelocityTransitionGroup, velocityHelpers } from 'velocity-react'; | |
const Animation = {}; | |
if (process.env.BROWSER) { | |
require('velocity-animate/velocity.ui'); | |
Animation.In = velocityHelpers.registerEffect({ | |
calls: [ | |
[{ | |
opacity: 1, | |
transformY: -100 | |
}, 1, { | |
easing: 'ease-in', | |
display: 'block' | |
}] | |
] | |
}); | |
Animation.Out = velocityHelpers.registerEffect({ | |
calls: [ | |
[{ | |
opacity: 0, | |
transformY: 100 | |
}, 1, { | |
easing: 'ease-out', | |
display: 'block' | |
}] | |
] | |
}); | |
} | |
function animateThing () { | |
const enterAnimation = { | |
animation: Animation.In || null, | |
duration: 1000, | |
}; | |
const leaveAnimation = { | |
animation: Animation.Out || null, | |
duration: 1000, | |
}; | |
return ( | |
<VelocityTransitionGroup runOnMount={true} enter={ enterAnimation } leave={ leaveAnimation }> | |
{ props.stateChange ? <Component /> : null } | |
</VelocityTransitionGroup> | |
); | |
} | |
export default animateThing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment