index.jsx 2.6 KB

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