Created
May 12, 2015 20:24
-
-
Save colinramsay/42d3dbd0316212d65161 to your computer and use it in GitHub Desktop.
react-router 0.13.2 TransitionGroup
This file contains hidden or 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
? ??meean what ??
fuck