Guest User

Untitled

a guest
May 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import React, { PropTypes } from 'react';
  2. import { TransitionMotion, spring } from 'react-motion';
  3.  
  4. /**
  5. * One example of using react-motion (0.3.0) within react-router (v1.0.0-rc3).
  6. *
  7. * Usage is simple, and really only requires two things–both of which are
  8. * injected into your app via react-router–pathname and children:
  9. *
  10. * <RouteTransition pathname={this.props.pathname}>
  11. * {this.props.children}
  12. * </RouteTransition>
  13. */
  14. const RouteTransition = React.createClass({
  15. propTypes: {
  16. pathname: PropTypes.string.isRequired
  17. },
  18.  
  19. willEnter() {
  20. return {
  21. handler: this.props.children,
  22. opacity: spring(0),
  23. scale: spring(0.95)
  24. };
  25. },
  26.  
  27. willLeave(key, value) {
  28. return {
  29. handler: value.handler,
  30. opacity: spring(0),
  31. scale: spring(0.95)
  32. };
  33. },
  34.  
  35. getStyles() {
  36. const { children, pathname } = this.props;
  37.  
  38. return {
  39. [pathname]: {
  40. handler: children,
  41. opacity: spring(1),
  42. scale: spring(1)
  43. }
  44. };
  45. },
  46.  
  47. render() {
  48. return (
  49. <TransitionMotion
  50. styles={this.getStyles()}
  51. willEnter={this.willEnter}
  52. willLeave={this.willLeave}
  53. >
  54. {interpolated =>
  55. <div>
  56. {Object.keys(interpolated).map(key =>
  57. <div
  58. key={`${key}-transition`}
  59. style={{
  60. position: 'absolute',
  61. opacity: interpolated[key].opacity,
  62. transform: `scale(${interpolated[key].scale})`
  63. }}
  64. >
  65. {interpolated[key].handler}
  66. </div>
  67. )}
  68. </div>
  69. }
  70. </TransitionMotion>
  71. );
  72. }
  73. });
  74.  
  75. module.exports = RouteTransition;
Add Comment
Please, Sign In to add comment