|
|
|
@ -1,27 +1,29 @@ |
|
|
|
|
import {PageContainer, PageContainerProps, View} from "@tarojs/components"; |
|
|
|
|
import {CSSProperties, FC, useEffect, useState} from "react"; |
|
|
|
|
import {CSSProperties, FC, useCallback, useEffect, useState} from "react"; |
|
|
|
|
import styles from './custom-page-container.module.scss' |
|
|
|
|
|
|
|
|
|
const PageContainerInner: FC<PageContainerProps> = (props) => { |
|
|
|
|
const [visible, setVisible] = useState(props.show) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (props.show != visible) { |
|
|
|
|
setVisible(props.show); |
|
|
|
|
if (visible !== props) { |
|
|
|
|
if (props.show) { |
|
|
|
|
setVisible(props.show) |
|
|
|
|
} else { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
setVisible(props.show) |
|
|
|
|
}, 300) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// todo 目前仅仅支持 after
|
|
|
|
|
if (!props.show) { |
|
|
|
|
(props.onBeforeLeave as Function)?.(); |
|
|
|
|
(props.onAfterLeave as Function)?.(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, [props.show]) |
|
|
|
|
|
|
|
|
|
if (!props.show) { |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const contentStyle = (): CSSProperties => { |
|
|
|
|
const contentStyle = useCallback((): CSSProperties => { |
|
|
|
|
let style: CSSProperties = {} |
|
|
|
|
|
|
|
|
|
switch (props.position) { |
|
|
|
@ -41,12 +43,30 @@ const PageContainerInner: FC<PageContainerProps> = (props) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return style |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
const childrenAnimation = useCallback(() => { |
|
|
|
|
switch (props.position) { |
|
|
|
|
case "top": |
|
|
|
|
case 'bottom': |
|
|
|
|
return props.show ? styles.childrenButton : styles.childrenButtonQuit |
|
|
|
|
case 'center': |
|
|
|
|
return props.show ? styles.childrenCenter : styles.childrenCenterQuit |
|
|
|
|
} |
|
|
|
|
}, [props.show]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className={styles.customPageContainer}> |
|
|
|
|
<View className={styles.overlay} onClick={props.onClickOverlay}></View> |
|
|
|
|
<View className={styles.content} style={contentStyle()}>{props.children}</View> |
|
|
|
|
<View |
|
|
|
|
className={styles.customPageContainer} |
|
|
|
|
style={`${visible ? 'display:flex' : 'display:none'}`}> |
|
|
|
|
<View |
|
|
|
|
className={`${styles.overlay} ${props.show ? styles.overlayEnter : styles.overlayQuit}`} |
|
|
|
|
onClick={props.onClickOverlay}/> |
|
|
|
|
<View |
|
|
|
|
className={`${styles.content} ${childrenAnimation()}`} |
|
|
|
|
style={contentStyle()}> |
|
|
|
|
{props.children} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|