|
|
@ -1,27 +1,29 @@ |
|
|
|
import {PageContainer, PageContainerProps, View} from "@tarojs/components"; |
|
|
|
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' |
|
|
|
import styles from './custom-page-container.module.scss' |
|
|
|
|
|
|
|
|
|
|
|
const PageContainerInner: FC<PageContainerProps> = (props) => { |
|
|
|
const PageContainerInner: FC<PageContainerProps> = (props) => { |
|
|
|
const [visible, setVisible] = useState(props.show) |
|
|
|
const [visible, setVisible] = useState(props.show) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (props.show != visible) { |
|
|
|
if (visible !== props) { |
|
|
|
setVisible(props.show); |
|
|
|
if (props.show) { |
|
|
|
|
|
|
|
setVisible(props.show) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
setVisible(props.show) |
|
|
|
|
|
|
|
}, 300) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo 目前仅仅支持 after
|
|
|
|
|
|
|
|
if (!props.show) { |
|
|
|
if (!props.show) { |
|
|
|
(props.onBeforeLeave as Function)?.(); |
|
|
|
(props.onBeforeLeave as Function)?.(); |
|
|
|
(props.onAfterLeave as Function)?.(); |
|
|
|
(props.onAfterLeave as Function)?.(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, [props.show]) |
|
|
|
}, [props.show]) |
|
|
|
|
|
|
|
|
|
|
|
if (!props.show) { |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const contentStyle = (): CSSProperties => { |
|
|
|
const contentStyle = useCallback((): CSSProperties => { |
|
|
|
let style: CSSProperties = {} |
|
|
|
let style: CSSProperties = {} |
|
|
|
|
|
|
|
|
|
|
|
switch (props.position) { |
|
|
|
switch (props.position) { |
|
|
@ -41,12 +43,30 @@ const PageContainerInner: FC<PageContainerProps> = (props) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return style |
|
|
|
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 ( |
|
|
|
return ( |
|
|
|
<View className={styles.customPageContainer}> |
|
|
|
<View |
|
|
|
<View className={styles.overlay} onClick={props.onClickOverlay}></View> |
|
|
|
className={styles.customPageContainer} |
|
|
|
<View className={styles.content} style={contentStyle()}>{props.children}</View> |
|
|
|
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> |
|
|
|
</View> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|