import { headerModel } from "@/model/header.model";
import {
View,
Text,
ScrollView,
CommonEventFunction,
} from "@tarojs/components";
import Taro from "@tarojs/taro";
import { clsx } from "clsx";
import { FC, memo, PropsWithChildren } from "react";
import { useRecoilValue } from "recoil";
import type { loadMoreConfig, refresherConfig } from "./hooks";
const PageLoader = memo(() => {
return (
Loading...
);
});
interface LayoutHeaderProps {
className?: string;
hideBack?: boolean;
}
// 自定义导航栏
const LayoutHeader = memo(
({
className,
hideBack = true,
children,
}: PropsWithChildren) => {
const header = useRecoilValue(headerModel);
const capsStyles = {
width: `${header.capsuleWidth}px`,
height: `${header.capsuleHeight}px`,
};
const handlerBack = () => {
Taro.navigateBack();
};
return (
{hideBack ? (
返回
) : null}
{children}
);
},
);
interface LayoutContainerProps {
className?: string;
refresherConfig?: refresherConfig;
refresherEnabled?: boolean;
loadMore?: loadMoreConfig;
onScroll?: CommonEventFunction;
}
// 页面容器
const LayoutContainer = memo(
({
className,
refresherConfig,
loadMore,
onScroll,
children,
}: PropsWithChildren) => {
return (
{children}
);
},
);
// 自定义页脚 底部安全区,暂时未适配 Android
const LayoutFooter = memo(({ children }: PropsWithChildren) => {
return (
{children}
);
});
interface LayoutProps {
loadding: boolean;
}
interface LayoutComponent extends FC> {
Header: FC>;
Footer: FC;
Container: FC>;
}
const LayoutBase = ({
children,
loadding = true,
}: PropsWithChildren) => {
if (loadding) {
return ;
}
return {children};
};
const Layout = LayoutBase as unknown as LayoutComponent;
Layout.Header = LayoutHeader;
Layout.Container = LayoutContainer;
Layout.Footer = LayoutFooter;
export default Layout;