index.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import PropTypes from "prop-types";
  2. import styles from "./styles.module.scss";
  3. import SvgIcon from "@components/SvgIcon";
  4. import {animated,easings} from "@react-spring/web";
  5. import {useState,useEffect} from "react";
  6. import {useSpring, useSpringRef} from "@react-spring/core";
  7. import {useLocation} from "react-router";
  8. const i18n=global.i18n;
  9. const SubScreen=({open,onClose,children,route,renderComp})=>{
  10. const [subOpen,setSubOpen]=useState(open);
  11. const {pathname,hash} = useLocation();
  12. const duration=200;
  13. const spref = useSpringRef()
  14. const delayClose=()=>{
  15. if (onClose)onClose();
  16. }
  17. const close=()=>{
  18. setSubOpen(false);
  19. // spref.start({
  20. // transform:'translateX(100%) translateZ(0px)',
  21. // })
  22. setTimeout(function () {
  23. delayClose();
  24. },duration);
  25. }
  26. // useEffect(()=>{
  27. // // extra.close=close;
  28. // // spref.start();
  29. // spref.start({
  30. // from: {transform: 'translateX(100%) translateZ(0px)'},
  31. // transform:subOpen?'translateX(0%) translateZ(0px)':'translateX(100%) translateZ(0px)',
  32. // })
  33. // },[pathname])
  34. const showAni=useSpring({
  35. // ref: spref,
  36. from: {transform: 'translateX(100%) translateZ(0px)'},
  37. transform:subOpen?'translateX(0%) translateZ(0px)':'translateX(100%) translateZ(0px)',
  38. config: {
  39. easing: easings.linear,
  40. duration:duration
  41. },
  42. });
  43. const renderHeader=()=>{
  44. let title=route?route.title:"";
  45. return (
  46. <div className={styles.header}>
  47. <button className={styles.close} onClick={()=>{
  48. close();
  49. }}>
  50. <SvgIcon className={styles.arrow} herf={"icon_Arrow"}/>
  51. </button>
  52. <div className={styles.hcontent}>
  53. {i18n.t(title)}
  54. </div>
  55. </div>
  56. )
  57. }
  58. const renderBar=()=>{
  59. return (
  60. <div id={'subbar'} className={styles.appbar}>
  61. {renderHeader()}
  62. </div>
  63. )
  64. }
  65. const renderContent=()=>{
  66. // addExtraChildProps(children);
  67. // let list=children.length==null?[children]:children;
  68. // // {children}
  69. return (
  70. <div className={styles.content}>
  71. {/*{children}*/}
  72. {renderComp({close})}
  73. </div>
  74. )
  75. }
  76. return (
  77. <animated.div className={styles.subscreen} style={showAni}>
  78. {renderBar()}
  79. {renderContent()}
  80. </animated.div>
  81. )
  82. }
  83. SubScreen.propTypes = {
  84. open: PropTypes.bool.isRequired,
  85. onClose: PropTypes.func.isRequired,
  86. // children: PropTypes.node.isRequired
  87. }
  88. export default SubScreen