Skip to content

Instantly share code, notes, and snippets.

@colinramsay
Created May 12, 2015 20:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save colinramsay/42d3dbd0316212d65161 to your computer and use it in GitHub Desktop.
Save colinramsay/42d3dbd0316212d65161 to your computer and use it in GitHub Desktop.
react-router 0.13.2 TransitionGroup
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>
@lazyTai
Copy link

lazyTai commented Sep 23, 2017

? ??meean what ??
fuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment