index.jsx 2.4 KB

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