/** * 频道选择(瞬间 / 长文共用) * 包含「发表至」入口行 + 展开后的频道单选面板。 */ import React from 'react'; import { View, TouchableOpacity, StyleSheet } from 'react-native'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { Text } from '../../../components/common'; import { spacing, fontSizes, borderRadius, useAppColors, type AppColors } from '../../../theme'; export type ChannelOption = { id: string; name: string }; interface ChannelPickerProps { channels: ChannelOption[]; selectedId: string | null; onSelect: (channelId: string) => void; expanded: boolean; onToggle: () => void; } export function ChannelPicker({ channels, selectedId, onSelect, expanded, onToggle, }: ChannelPickerProps) { const colors = useAppColors(); const styles = React.useMemo(() => createChannelPickerStyles(colors), [colors]); const selectedName = React.useMemo(() => { if (!selectedId) return ''; return channels.find(c => c.id === selectedId)?.name || ''; }, [selectedId, channels]); return ( <> {/* 入口行 */} 发表至: {selectedName || '选择频道'} {/* 展开面板 */} {expanded && ( {channels.map((channel) => { const isSelected = selectedId === channel.id; return ( onSelect(channel.id)} > {channel.name} ); })} {channels.length === 0 && ( 暂无可用频道 )} )} ); } function createChannelPickerStyles(colors: AppColors) { return StyleSheet.create({ channelEntryRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: spacing.lg, paddingVertical: spacing.sm, borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: colors.divider, backgroundColor: colors.background.paper, }, channelEntryLabel: { fontSize: fontSizes.md, }, channelEntryValueWrap: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs, }, channelEntryValue: { fontSize: fontSizes.md, }, tagsSection: { paddingHorizontal: spacing.lg, paddingTop: spacing.md, paddingBottom: spacing.sm, borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: colors.divider, backgroundColor: colors.background.paper, }, tagsContainer: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm, }, tag: { backgroundColor: colors.background.default, borderRadius: borderRadius.full, paddingHorizontal: spacing.md, paddingVertical: spacing.xs, borderWidth: 1, borderColor: colors.divider, }, channelSelected: { backgroundColor: colors.primary.main, borderColor: colors.primary.main, }, tagText: { fontWeight: '500', }, }); }