mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-15 12:24:44 +08:00
139 lines
3.7 KiB
TypeScript
139 lines
3.7 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { View, StyleSheet, TouchableOpacity, Text, Platform } from 'react-native';
|
|
import { useRouter, usePathname } from 'expo-router';
|
|
import { Home, Search, Heart, Settings, Tv } from 'lucide-react-native';
|
|
import { Colors } from '@/constants/Colors';
|
|
import { useResponsiveLayout } from '@/hooks/useResponsiveLayout';
|
|
import { DeviceUtils } from '@/utils/DeviceUtils';
|
|
|
|
interface TabItem {
|
|
key: string;
|
|
label: string;
|
|
icon: React.ComponentType<any>;
|
|
route: string;
|
|
}
|
|
|
|
const tabs: TabItem[] = [
|
|
{ key: 'home', label: '首页', icon: Home, route: '/' },
|
|
{ key: 'search', label: '搜索', icon: Search, route: '/search' },
|
|
{ key: 'live', label: '直播', icon: Tv, route: '/live' },
|
|
{ key: 'favorites', label: '收藏', icon: Heart, route: '/favorites' },
|
|
{ key: 'settings', label: '设置', icon: Settings, route: '/settings' },
|
|
];
|
|
|
|
interface MobileTabContainerProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const MobileTabContainer: React.FC<MobileTabContainerProps> = ({ children }) => {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const { spacing } = useResponsiveLayout();
|
|
|
|
const handleTabPress = (route: string) => {
|
|
if (route === '/') {
|
|
router.push('/');
|
|
} else {
|
|
router.push(route as any);
|
|
}
|
|
};
|
|
|
|
const isTabActive = (route: string) => {
|
|
if (route === '/' && pathname === '/') return true;
|
|
if (route !== '/' && pathname === route) return true;
|
|
return false;
|
|
};
|
|
|
|
const dynamicStyles = createStyles(spacing);
|
|
|
|
return (
|
|
<View style={dynamicStyles.container}>
|
|
{/* 内容区域 */}
|
|
<View style={dynamicStyles.content}>
|
|
{children}
|
|
</View>
|
|
|
|
{/* 底部导航栏 */}
|
|
<View style={dynamicStyles.tabBar}>
|
|
{tabs.map((tab) => {
|
|
const isActive = isTabActive(tab.route);
|
|
const IconComponent = tab.icon;
|
|
|
|
return (
|
|
<TouchableOpacity
|
|
key={tab.key}
|
|
style={[dynamicStyles.tab, isActive && dynamicStyles.activeTab]}
|
|
onPress={() => handleTabPress(tab.route)}
|
|
activeOpacity={0.7}
|
|
>
|
|
<IconComponent
|
|
size={20}
|
|
color={isActive ? Colors.dark.primary : '#888'}
|
|
strokeWidth={isActive ? 2.5 : 2}
|
|
/>
|
|
<Text style={[
|
|
dynamicStyles.tabLabel,
|
|
isActive && dynamicStyles.activeTabLabel
|
|
]}>
|
|
{tab.label}
|
|
</Text>
|
|
</TouchableOpacity>
|
|
);
|
|
})}
|
|
</View>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
const createStyles = (spacing: number) => {
|
|
const minTouchTarget = DeviceUtils.getMinTouchTargetSize();
|
|
|
|
return StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
},
|
|
content: {
|
|
flex: 1,
|
|
},
|
|
tabBar: {
|
|
flexDirection: 'row',
|
|
backgroundColor: '#1c1c1e',
|
|
borderTopWidth: 1,
|
|
borderTopColor: '#333',
|
|
paddingTop: spacing / 2,
|
|
paddingBottom: Platform.OS === 'ios' ? spacing * 2 : spacing,
|
|
paddingHorizontal: spacing,
|
|
shadowColor: '#000',
|
|
shadowOffset: {
|
|
width: 0,
|
|
height: -2,
|
|
},
|
|
shadowOpacity: 0.1,
|
|
shadowRadius: 4,
|
|
elevation: 10,
|
|
},
|
|
tab: {
|
|
flex: 1,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
minHeight: minTouchTarget,
|
|
paddingVertical: spacing / 2,
|
|
borderRadius: 8,
|
|
},
|
|
activeTab: {
|
|
backgroundColor: 'rgba(64, 156, 255, 0.1)',
|
|
},
|
|
tabLabel: {
|
|
fontSize: 11,
|
|
color: '#888',
|
|
marginTop: 2,
|
|
fontWeight: '500',
|
|
},
|
|
activeTabLabel: {
|
|
color: Colors.dark.primary,
|
|
fontWeight: '600',
|
|
},
|
|
});
|
|
};
|
|
|
|
export default MobileTabContainer; |