import AppContext from "@/context/appContext";
import BottomBarContext from "@/context/bottomBarContext";
import UserHelper from "@/helper/userHelper";
import useStore from "@/hooks/useRedux";
import RouteUtil from "@/utils/routeUtil";
import { FixedView } from "@taroify/core";
import { Image, View, ViewProps } from "@tarojs/components";
import { pxTransform } from "@tarojs/taro";
import classNames from "classnames";
import { PropsWithChildren, useContext } from "react";
import Flex from "../flex";
import Label from "../label";
import "./index.scss";
interface ILayoutProps extends ViewProps {
safe?: boolean;
bottomBarIndex?: number;
}
const BottomNavBar = () => {
const appContext = useContext(AppContext);
const bottomBarContext = useContext(BottomBarContext);
const menu = useStore((p) => p.tabMenu);
return (
{menu.map((p) => {
let _index = ["home", "official_account", "user_center"].findIndex(
(sp) => sp === p.code
);
return (
{
UserHelper.afterLogin({
forceLogin: false,
callback: async () => {
if (
["home", "official_account", "user_center"].includes(
p.code
)
) {
bottomBarContext.switchTo(_index as number);
} else {
RouteUtil.toWebViewPage({
url: p.jumpTarget,
});
}
},
});
return;
}}
flex={1}
alignItem="center"
justifyContent="center"
>
);
})}
);
};
const InternalLayout = (props: PropsWithChildren) => {
const { bottomBarIndex, safe = false, ...viewProps } = props;
const appContext = useContext(AppContext);
const bottomBarContext = useContext(BottomBarContext);
const safeStyle: React.CSSProperties = {};
if (safe) {
safeStyle.paddingTop = appContext.padding.top;
safeStyle.paddingBottom = appContext.padding.bottom; //(appContext.systemInfo?.screenHeight || 0) - (appContext.systemInfo?.safeArea?.bottom || 0);
}
return (
{props.children}
{props.bottomBarIndex !== undefined && }
);
};
type InternalLayoutType = typeof InternalLayout;
interface LayoutInterface extends InternalLayoutType {}
const Layout = InternalLayout as LayoutInterface;
export default Layout;