54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import type { icons } from 'lucide-react-native'
|
|
import { router, useNavigation } from 'expo-router'
|
|
import { create } from 'zustand'
|
|
|
|
export interface NavItem {
|
|
label: string
|
|
path: string
|
|
icon: keyof typeof icons
|
|
}
|
|
|
|
interface NavState {
|
|
navMenus: NavItem[]
|
|
pathname: string
|
|
replace: (p: string) => void
|
|
setPathname: (p: string) => void
|
|
navigateToAuth: () => void
|
|
navigateTo: (p: string) => void
|
|
setNavMenus: (menus: NavItem[]) => void
|
|
}
|
|
|
|
const DEFAULT_NAV_MENUS: NavItem[] = [
|
|
{ label: '记账', path: '/finance', icon: 'CircleDollarSign' },
|
|
// { label: '恋爱记', path: '/love', icon: 'Heart' },
|
|
// { label: '聊天', path: '/chat', icon: 'MessageCircle' },
|
|
{ label: '空间管理', path: '/space', icon: 'Earth' },
|
|
{ label: '个人中心', path: '/user', icon: 'CircleUserRound' },
|
|
]
|
|
|
|
export const useNavStore = create<NavState>()(
|
|
(set, get) => ({
|
|
pathname: '/',
|
|
navMenus: DEFAULT_NAV_MENUS,
|
|
|
|
setPathname: (p: string) => set({ pathname: p }),
|
|
navigateToAuth: () => {
|
|
const pathname = useNavStore.getState().pathname
|
|
|
|
if (pathname !== '/auth') {
|
|
router.replace('/auth')
|
|
}
|
|
},
|
|
navigateTo: (p: string) => {
|
|
router.navigate(p)
|
|
},
|
|
replace: (p: string) => {
|
|
if (router.canDismiss()) {
|
|
router.dismissAll()
|
|
}
|
|
router.replace(p)
|
|
},
|
|
setNavMenus: navMenus => set({ navMenus }),
|
|
}),
|
|
)
|