feat: 引入路由常量并更新相关页面导航
- 新增 ROUTES 常量文件,集中管理应用路由 - 更新多个页面的导航逻辑,使用 ROUTES 常量替代硬编码路径 - 修改教练页面和今日训练页面的路由,提升代码可维护性 - 优化标签页和登录页面的导航,确保一致性和易用性
This commit is contained in:
@@ -7,6 +7,7 @@ import { IconSymbol } from '@/components/ui/IconSymbol';
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { TAB_BAR_BOTTOM_OFFSET, TAB_BAR_HEIGHT } from '@/constants/TabBar';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
import { ROUTES } from '@/constants/Routes';
|
||||
|
||||
export default function TabLayout() {
|
||||
const theme = (useColorScheme() ?? 'light') as 'light' | 'dark';
|
||||
@@ -17,9 +18,9 @@ export default function TabLayout() {
|
||||
<Tabs
|
||||
screenOptions={({ route }) => {
|
||||
const routeName = route.name;
|
||||
const isSelected = (routeName === 'index' && pathname === '/') ||
|
||||
(routeName === 'coach' && pathname === '/coach') ||
|
||||
(routeName === 'statistics' && pathname === '/statistics') ||
|
||||
const isSelected = (routeName === 'index' && pathname === ROUTES.TAB_HOME) ||
|
||||
(routeName === 'coach' && pathname === ROUTES.TAB_COACH) ||
|
||||
(routeName === 'statistics' && pathname === ROUTES.TAB_STATISTICS) ||
|
||||
pathname.includes(routeName);
|
||||
|
||||
return {
|
||||
@@ -39,7 +40,7 @@ export default function TabLayout() {
|
||||
const getIconAndTitle = () => {
|
||||
switch (routeName) {
|
||||
case 'index':
|
||||
return { icon: 'house.fill', title: '首页' } as const;
|
||||
return { icon: 'magnifyingglass.circle.fill', title: '发现' } as const;
|
||||
case 'coach':
|
||||
return { icon: 'person.3.fill', title: 'Bot' } as const;
|
||||
case 'statistics':
|
||||
@@ -157,12 +158,12 @@ export default function TabLayout() {
|
||||
<Tabs.Screen
|
||||
name="index"
|
||||
options={{
|
||||
title: '首页',
|
||||
title: '发现',
|
||||
tabBarIcon: ({ color }) => {
|
||||
const isHomeSelected = pathname === '/' || pathname === '/index';
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||
<IconSymbol size={22} name="house.fill" color={color} />
|
||||
<IconSymbol size={22} name="magnifyingglass.circle.fill" color={color} />
|
||||
{isHomeSelected && (
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
@@ -174,7 +175,7 @@ export default function TabLayout() {
|
||||
textAlign: 'center',
|
||||
flexShrink: 0,
|
||||
}}>
|
||||
首页
|
||||
发现
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user