import { ScrollView, View, Text } from "@tarojs/components"; import './layout.scss' import { NaviBarTitleShowType, TemplateType } from "@/utils/types"; import { useEffect, useState } from "react"; import Taro, { usePageScroll } from "@tarojs/taro"; let useNavigation; if (process.env.TARO_ENV == 'rn') { useNavigation = require("@react-navigation/native").useNavigation } export default function Layout(props: { children: React.ReactNode, type: TemplateType, refresh?: Function, more?: Function, triggered?: boolean, title?: string, titleColor?: string, header?: React.ReactNode, secondPage?: boolean, isFastSleepTheme?: boolean, titleShowStyle: NaviBarTitleShowType }) { const { children, type, triggered } = props; const [showTitle, setShowTitle] = useState(props.titleShowStyle == NaviBarTitleShowType.alwayShow) let navigation; if (useNavigation) { navigation = useNavigation() } useEffect(() => { Taro.setNavigationBarTitle({ title: showTitle ? props.title ? props.title : '' : '' }) if (navigation) { navigation.setOptions({ headerTitle: showTitle ? props.title ? props.title : '' : '', }); } }, [showTitle]) function onScroll(e) { console.log('a') if (props.titleShowStyle == NaviBarTitleShowType.scrollToShow) { if (e.detail.scrollTop > 70) { setShowTitle(true) } else { setShowTitle(false) } } } usePageScroll((e) => { if (props.titleShowStyle == NaviBarTitleShowType.scrollToShow) { if (e.scrollTop > 70) { setShowTitle(true) } else { setShowTitle(false) } } }) function pageDetail() { return { props.title && { props.isFastSleepTheme ? {props.title} : {props.title} } } { children } } switch (type) { case TemplateType.list: return { props.refresh!() }} upperThreshold={50} onScrollToLower={() => { props.more ? props.more() : null }} refresherTriggered={triggered}> { props.title && {props.title} } {children} case TemplateType.grid: return { props.refresh!() }} upperThreshold={50} onScrollToLower={() => { props.more ? props.more() : null }} refresherTriggered={triggered}> { props.title && {props.title} } {children} case TemplateType.flex: return {/* */} { process.env.TARO_ENV == 'weapp' ? pageDetail() : { pageDetail() } } case TemplateType.customHeader: return {/* */} { props.header } {children} } return }