-
-
Save mattsahr/d88c7e868c92dde2757e to your computer and use it in GitHub Desktop.
ReactJS -- Animation Wrapper Class
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
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