Skip to content

Instantly share code, notes, and snippets.

@gtwalford
Last active June 29, 2016 23:39
Show Gist options
  • Save gtwalford/65144ca0a9e4970867d1000b6e4b836e to your computer and use it in GitHub Desktop.
Save gtwalford/65144ca0a9e4970867d1000b6e4b836e to your computer and use it in GitHub Desktop.
Velocity registerEffects w/ server-side React
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