Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import React from "react";
  2. import { Switch } from "react-router-dom";
  3. import posed, { PoseGroup } from "react-pose";
  4. import "./styles.css";
  5.  
  6. /**
  7. * This component is used to control the routing animation.
  8. * It controls what should happen after animation complete (onRest).
  9. * It differs animation direction based on routePopped props. (Set in router.action.js and available from routerReducer).
  10. * @param location React router location used as key in Switch
  11. * @param children All routes (set in Routes.js)
  12. * @param routePopped Used to manage direction of animation
  13. * @param rest All other props sent down
  14. */
  15. export const AnimatedSwitch = ({ history, location, children, ...rest }) => {
  16. const reverse = location.pathname === "/";
  17.  
  18. return (
  19. <PoseGroup
  20. flipMove={false}
  21. preEnterPose={reverse ? "leftSide" : "rightSide"}
  22. exitPose={reverse ? "rightSide" : "leftSide"}
  23. >
  24. <ContextRouteAnimation key={location.pathname} reverse={reverse}>
  25. <Switch location={location} {...rest}>
  26. {children}
  27. </Switch>
  28. </ContextRouteAnimation>
  29. </PoseGroup>
  30. );
  31. };
  32.  
  33. export default AnimatedSwitch;
  34.  
  35.  
  36. /**
  37. * Try to change up the different commented values for varying animatmions
  38. */
  39. export const ContextRouteAnimation = posed.div({
  40. enter: {
  41. x: 0,
  42. // opacity: 1,
  43. // scale: 1,
  44. transition: {
  45. type: "tween",
  46. ease: "easeInOut",
  47. duration: 400
  48. }
  49. },
  50. leftSide: {
  51. x: "-100%",
  52. // opacity: 0,
  53. // scale: 1.5,
  54. transition: {
  55. type: "tween",
  56. ease: "easeInOut",
  57. duration: 400
  58. }
  59. },
  60. rightSide: {
  61. x: "100%",
  62. // opacity: 0,
  63. // scale: 1.5,
  64. transition: {
  65. type: "tween",
  66. ease: "easeInOut",
  67. duration: 400
  68. }
  69. }
  70. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement