Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsahr/d88c7e868c92dde2757e to your computer and use it in GitHub Desktop.
Save mattsahr/d88c7e868c92dde2757e to your computer and use it in GitHub Desktop.
ReactJS -- Animation Wrapper Class
let AnimationWrapper = React.createClass({
render() {
console.log(this.props.childClassName + ' render');
return this.props.children;
},
componentWillAppear (callback) {
console.log(this.props.childClassName + ' willappear');
callback();
},
componentDidAppear () {
console.log(this.props.childClassName + ' didappear');
},
componentWillEnter (callback) {
console.log(this.props.childClassName + ' willenter');
let el = this.getDOMNode();
el.classList.add(this.props.prefix + '-enter');
el.classList.add(this.props.prefix + '-enter-active');
el.addEventListener('webkitAnimationEnd', () => {
console.log(this.props.childClassName + ' willappear webkitAnimationEnd');
callback();
});
},
componentDidEnter() {
console.log(this.props.childClassName + ' didenter');
let el = this.getDOMNode();
el.classList.remove(this.props.prefix + '-enter');
el.classList.remove(this.props.prefix + '-enter-active');
},
componentWillLeave (callback) {
console.log(this.props.childClassName + ' willleave');
let el = this.getDOMNode();
el.addEventListener('webkitAnimationEnd', () => {
console.log(this.props.childClassName + ' transitionend');
callback();
}, false);
el.classList.add(this.props.prefix + '-leave');
el.classList.add(this.props.prefix + '-leave-active');
},
componentDidLeave() {
console.log(this.props.childClassName + ' didleave');
let el = this.getDOMNode();
el.classList.remove(this.props.prefix + '-leave');
el.classList.remove(this.props.prefix + '-leave-active');
}
});
let App = React.createClass({
contextTypes: {
router: React.PropTypes.func
},
render() {
var routeStack = this.context.router.getCurrentRoutes();
var name = routeStack[routeStack.length - 1].name;
return <TransitionGroup component="div">
<AnimationWrapper key={name} prefix="page">
<RouteHandler />
</AnimationWrapper>
</TransitionGroup>
}
});
let Routes = <Route name="app" handler={App} path="/">...more routes</Route>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment