File size: 4,583 Bytes
4a5ef51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import React from 'react';
import { View, Text, Pressable, StyleSheet } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import Svg, { Circle, Line, Path, Polyline, Rect } from 'react-native-svg';
import { colors } from './theme';
export type TabKey = 'device' | 'camera' | 'stream' | 'system' | 'console';
const tabs: { key: TabKey; label: string; icon: (active: boolean) => React.ReactNode }[] = [
{
key: 'device',
label: 'Device',
icon: (active) => (
<Svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke={active ? '#fff' : colors.muted} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
<Path d="m6.5 6.5 11 11L12 23V1l5.5 5.5-11 11" />
</Svg>
),
},
{
key: 'camera',
label: 'Camera',
icon: (active) => (
<Svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke={active ? '#fff' : colors.muted} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
<Path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z" />
<Circle cx={12} cy={13} r={4} />
</Svg>
),
},
{
key: 'stream',
label: 'Stream',
icon: (active) => (
<Svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke={active ? '#fff' : colors.muted} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
<Circle cx={12} cy={12} r={2} />
<Path d="M16.24 7.76a6 6 0 0 1 0 8.49M7.76 16.24a6 6 0 0 1 0-8.48M20.49 4.93a10 10 0 0 1 0 14.14M3.51 19.07a10 10 0 0 1 0-14.14" />
</Svg>
),
},
{
key: 'system',
label: 'System',
icon: (active) => (
<Svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke={active ? '#fff' : colors.muted} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
<Rect x={3} y={3} width={7} height={7} rx={1.5} />
<Rect x={14} y={3} width={7} height={7} rx={1.5} />
<Rect x={3} y={14} width={7} height={7} rx={1.5} />
<Rect x={14} y={14} width={7} height={7} rx={1.5} />
</Svg>
),
},
{
key: 'console',
label: 'Console',
icon: (active) => (
<Svg width={20} height={20} viewBox="0 0 24 24" fill="none" stroke={active ? '#fff' : colors.muted} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
<Polyline points="4 17 10 11 4 5" />
<Line x1={12} y1={19} x2={20} y2={19} />
</Svg>
),
},
];
export function TabBar({ active, onChange }: { active: TabKey; onChange: (k: TabKey) => void }) {
return (
<View style={styles.outer}>
{tabs.map((t) => {
const isActive = t.key === active;
const inner = (
<View style={[styles.tab, isActive && styles.tabActive]}>
{t.icon(isActive)}
<Text style={[styles.label, { color: isActive ? '#fff' : colors.muted, fontWeight: isActive ? '600' : '500' }]}>{t.label}</Text>
</View>
);
return (
<Pressable key={t.key} onPress={() => onChange(t.key)} style={styles.tabWrap}>
{isActive ? (
<LinearGradient colors={['#1F3A2A', '#28473A']} style={styles.gradientTab}>
{t.icon(true)}
<Text style={[styles.label, { color: '#fff', fontWeight: '600' }]}>{t.label}</Text>
</LinearGradient>
) : (
inner
)}
</Pressable>
);
})}
</View>
);
}
const styles = StyleSheet.create({
outer: {
position: 'absolute',
left: 12,
right: 12,
bottom: 12,
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'rgba(255,255,255,0.85)',
borderRadius: 30,
borderWidth: 1,
borderColor: 'rgba(255,255,255,0.8)',
padding: 8,
gap: 4,
shadowColor: '#0F2A1D',
shadowOpacity: 0.14,
shadowOffset: { width: 0, height: 14 },
shadowRadius: 44,
elevation: 12,
},
tabWrap: { flex: 1, minHeight: 60 },
tab: {
minHeight: 58,
paddingVertical: 10,
paddingHorizontal: 8,
alignItems: 'center',
justifyContent: 'center',
gap: 4,
borderRadius: 22,
},
tabActive: {
backgroundColor: '#28473A',
},
gradientTab: {
minHeight: 58,
paddingVertical: 10,
paddingHorizontal: 8,
alignItems: 'center',
justifyContent: 'center',
gap: 4,
borderRadius: 22,
},
label: {
fontSize: 11,
lineHeight: 13,
},
});
|